简体   繁体   中英

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. After much investigation, I have narrowed down the problem to one point: transforming a ArrayBuffer to a Blob. This is working with Chrome on Windows (the xhr.responseType being 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). Any idea?

I'm not sure Blob is actually available on 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.

So I have found an alternative solution to store locally a file from an URL, using FileTransfer , thanks to GitHub Gists. I adapted a snippet I have found here:

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

So thank you, Nathan...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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