Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 699
J.V. Avatar asked Jan 15 '13 15:01

J.V.


1 Answers

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.

like image 95
Rob Juurlink Avatar answered Oct 18 '22 13:10

Rob Juurlink