简体   繁体   English

从arraybuffer到Cordova中的Blob

[英]From arraybuffer to blob in Cordova

I'm trying to save locally (using LocalFileSystem) a picture (I retrieve from an URL with XMLHttpRequest) with Cordova. 我正在尝试使用Cordova在本地保存图片(使用LocalFileSystem)(通过XMLHttpRequest从URL检索图片)。 After much investigation, I have narrowed down the problem to one point: transforming a ArrayBuffer to a Blob. 经过大量研究,我将问题缩小为一点:将ArrayBuffer转换为Blob。 This is working with Chrome on Windows (the xhr.responseType being arraybuffer): 这适用于Windows上的Chrome(xhr.responseType为arraybuffer):

var blob = new Blob([xhr.response], {type: 'image/jpeg'});

But it's not working with Cordova (2.9.0) on iOS (XCode iOS 6.1 simulator). 但是,它不适用于iOS(XCode iOS 6.1模拟器)上的Cordova(2.9.0)。 Any idea? 任何想法?

I'm not sure Blob is actually available on Cordova. 我不确定Bord是否确实在Cordova上可用。 I can't find any reference in the official documentation, even if some forum discussions mention it. 即使在某些论坛讨论中提到它,我也无法在官方文档中找到任何参考。 Anyway, i don't think Cordova is able to save a JPEG file using a Blob as for the 2.9.0 version I'm currently using. 无论如何,我不认为Cordova能够使用Blob来保存JPEG文件,因为我目前正在使用2.9.0版本。

So I have found an alternative solution to store locally a file from an URL, using FileTransfer , thanks to GitHub Gists. 因此,由于有了GitHub Gists,我找到了一个替代解决方案,可以使用FileTransfer使用URL从本地存储文件。 I adapted a snippet I have found here: 我修改了我在这里找到的代码片段:

https://gist.github.com/nathanpc/2464060 https://gist.github.com/nathanpc/2464060

So thank you, Nathan... 谢谢你,内森...

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

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