blob does not accept Uint8Array on ios

后端 未结 1 763
孤城傲影
孤城傲影 2021-01-17 22:39

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 no

相关标签:
1条回答
  • 2021-01-17 23:03

    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.

    0 讨论(0)
提交回复
热议问题