javascript - 有没有办法在 Flutter 上启动 blob url?
问题描述
我有一个网络应用程序,可根据用户请求查询后端 api 以获取 pdf,然后将其显示在单独的浏览器选项卡中。此代码有效(代码路径 when isFlutterApp=false
),如下所示:
let pdf = await Api.getReceiptAsPdf(receipt.id);
var file = new Blob([pdf], {type: 'application/pdf'});
var fileURL = URL.createObjectURL(file);
//fileURL looks like: blob:https://my.example.com/2e48a922-513d-4cb4-8e1f-148d6b7d2640
if (isFlutterApp) sendFlutterNotification(fileURL);
else window.open(fileURL);
Web 应用也可以在 Flutter App 中运行(在 Flutter Web 视图中),然后上面的代码将 fileURL 发送到 Flutter App,而不是调用 window.open。在这种情况下,我使用url_launcher并通过 Flutter 打开相同的 fileUrl:
//fileURL is (e.g.) blob:https://my.example.com/2e48a922-513d-4cb4-8e1f-148d6b7d2640
void _launchURL(u) async =>
await canLaunch(u) ? await launch(u) : throw 'Could not launch $u';
这不起作用,我得到:
-canOpenURL: failed for URL: "blob:https://my.example.com/2e48a922-513d-4cb4-8e1f-148d6b7d2640" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
[VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: Could not launch blob:https://my.example.com/2e48a922-513d-4cb4-8e1f-148d6b7d2640
#0 _MyState._launchURL (package:flutterwrapper/main.dart:173:46)
到目前为止,我只在 ios 上对此进行了测试,并在 info.plist 中添加了以下条目:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>blob</string>
</array>
这里可能是什么问题?
解决方案
推荐阅读
- python - 如何删除熊猫数据框中的每一行?
- laravel - Laravel:$request->all() 和 $request->input() 之间的区别
- javascript - 是否可以从公共 CDN 提供压缩的 js/css 文件?
- python-sphinx - Readthedocs / Sphinx 不从 rst 文件中呈现项目符号列表
- javascript - 如何将 TypeScript 代码编译成单个 .js 文件,可通过“node mycode.js”执行?
- html - 如何使用 WSQL 事务方法获取值,可以创建表但值不能上传
- laravel - Laravel 8 共享主机中缺少混合清单文件
- php - 我们可以在管理中使用 API 来管理这些数据吗?
- algorithm - 有多少种方法可以实现贝尔曼福特算法?
- android - 与 RecyclerView 的数据绑定未正确呈现