如何使用 Javascript 从 Chrome iOS 下载 blob 文件?
我正在从 iOS 下载文件(pdf、excel、txt、png)。 iOS 没有文件系统,这对下载来说是个问题。 如果需要,我创建了一个代码,它根据操作系统和导航器下载 blob 文件。它在桌面(最新版本的 Chrome 和 IE)、移动 Android(Chrome、原生导航器)和 iOS iPad2 (Safari) 上运行良好。
现在,Chrome iOS 应该像 Safari mobile,但算法不起作用,Chrome iO 通过在新选项卡中打开来下载文件,但页面是空的。
I create my own blob to create the downloadUrl.
This is a part of the download function .
var URL = window.URL || window.webkitURL;
var downloadUrl = URL.createObjectURL(iobBLOB);
var newWindow = null;
if (typeof a.download === 'undefined') {
var newWindow = null;
newWindow = window.open(downloadUrl, '_blank');
setTimeout(function() {
newWindow.document.title = isbFilename;
}, 10);
}
更多详情
Debugging on iPad 2 and iPhone 4
Trying to download an excell, pdf, txt, and Png files.
The devices doesn't have file system.
感谢您帮助我...如果您需要更多信息,请告诉我这是我的第一个问题。
最佳答案
经过搜索,这个解决方案似乎在 ChromeiOS 和 Safari 上运行良好。我在这篇文章中找到了它 How to open Blob URL on Chrome iOS .这解决了我的问题:
//isbContentType i.e. 'text/plain'
//isbFilename i.e. 'This is a title'
var reader = new FileReader();
reader.onload = function(e) {
var bdata = btoa(reader.result);
var datauri = 'data:' + isbContentType + ';base64,' + bdata;
window.open(datauri);
newWindow = setTimeout(function() {
newWindow.document.title = isbFilename;
}, 10);
};
reader.readAsBinaryString(iobBLOB);
我相信有一种方法可以下载 blob 文件,但事实并非如此。还是谢谢
关于javascript - 如何使用 Javascript 从 Chrome iOS 下载 blob 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29134418/