简体   繁体   中英

blob does not accept Uint8Array on ios

I try to create a Blob object and pass an Uint8Array to it's constructor It works fine on chrome and firefox on windows In chrome and safari on ios however the Blod does not contain the data of the Uint8Array but the text : [object Uint8Array]

I need this to upload a canvas to the server.

Is there a workaround?

I'm struggling with the exact same problem. When I backup the Uint8Array with an ArrayBuffer, it does work in both Safari and Chrome (not tested in other browsers yet) but Chrome prints a warning message. Chrome says I have to wrap ArrayBuffer in a DataView before passing it to Blob() constructor.

// write the bytes of the string to an ArrayBuffer
var ab = new ArrayBuffer(byteString.length);
var ia = new Uint8Array(ab);
for (var i = 0; i < byteString.length; i++) {
    ia[i] = byteString.charCodeAt(i);
}

new Blob([ab], {type: mimeString});

Edit

The exact Chrome deprecation message is:

ArrayBuffer values are deprecated in Blob Constructor. Use ArrayBufferView instead.

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