简体   繁体   English

blob不接受ios上的Uint8Array

[英]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] 我尝试创建一个Blob对象并将Uint8Array传递给它的构造函数它在Chrome上的chrome和firefox工作正常在ios上的chrome和safari但是Blod不包含Uint8Array的数据但文本:[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. 当我使用ArrayBuffer备份Uint8Array时, 它在Safari和Chrome中都有效 (尚未在其他浏览器中测试过),但Chrome会打印一条警告消息。 Chrome says I have to wrap ArrayBuffer in a DataView before passing it to Blob() constructor. Chrome说我必须在将DataBuffer传递给Blob()构造函数之前将其封装在DataView中。

// 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: 确切的Chrome弃用邮件是:

ArrayBuffer values are deprecated in Blob Constructor. Blob构造函数中不推荐使用ArrayBuffer值。 Use ArrayBufferView instead. 请改用ArrayBufferView。

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

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