简体   繁体   English

在 Cordova InAppBrowser 上打开 createObjectURL Blob

[英]Open createObjectURL Blob on Cordova InAppBrowser

I have an Angular2+/Cordova app, and I'm making an API request to get a PDF.我有一个 Angular2+/Cordova 应用程序,我正在发出 API 请求以获取 PDF。 I'd like to open this PDF in Web + Native environments.我想在 Web + Native 环境中打开此 PDF。

For web I'm opening the window, getting the PDF & creating a Blob from it, then doing createObjectURL and setting the window's location.href to that URL.对于网络,我打开窗口,获取 PDF 并从中创建一个 Blob,然后执行createObjectURL并将窗口的location.href设置为该 URL。 It works well (on Chrome/FF).它运行良好(在 Chrome/FF 上)。

On native I'd like to do something similar, but ideally just do a window.open (via the InAppBrowser plugin) with the URL that came from createObjectURL .在本机上,我想做类似的事情,但理想情况下只需使用来自createObjectURL的 URL 执行 window.open(通过InAppBrowser插件)。 Is this possible?这可能吗? The URL I get back is something like: blob:file:///ef76ad0d-7c7f-4817-915f-9097160d1a58 .我返回的 URL 类似于: blob:file:///ef76ad0d-7c7f-4817-915f-9097160d1a58 Trying to open this via InAppBrowser with a _system target does absolutely nothing.尝试通过 InAppBrowser 使用_system目标打开它绝对没有任何作用。 No errors, no windows, no nothing.没有错误,没有窗口,什么都没有。 Wondering if there are special whitelist or SCP things I need to do for this?想知道我是否需要为此做特殊的白名单或 SCP 事情?

For reference, I don't like this solution, but I ended up treating web and native differently in this case.作为参考,我不喜欢这个解决方案,但在这种情况下,我最终以不同的方式对待 web 和 native。

WEB: Open Window --> REST call to get Blob --> createObjectURL with Blob --> set window location href to result of previous step WEB:打开窗口 --> REST 调用以获取 Blob --> createObjectURL with Blob --> 将窗口位置 href 设置为上一步的结果

NATIVE: REST call to get Blob --> Save Blob with Cordova File plugin --> Open saved file with Cordova File Opener plugin原生:REST 调用以获取 Blob --> 使用 Cordova File 插件保存 Blob --> 使用 Cordova File Opener 插件打开保存的文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM