blob不接受ios上的Uint8Array [英] blob does not accept Uint8Array on ios

查看:703
本文介绍了blob不接受ios上的Uint8Array的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试创建一个Blob对象,并将一个Uint8Array传递给它的构造函数
它可以在windows
上的chrome和firefox上正常工作但是在ios上的chrome和safari上,但是Blod不包含Uint8Array,但文本:[对象Uint8Array]

我需要这个上传一个画布到服务器。



是否有解决方法?

解决方案

我正在努力解决完全相同的问题。当我使用ArrayBuffer备份Uint8Array时,它可以在Safari和Chrome中使用(尚未在其他浏览器中测试过),但Chrome会打印警告消息。 Chrome说我必须在传递给Blob()构造函数之前将ArrayBuffer包装在DataView中。

  //将字节字符串到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);
}

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

编辑

确切的Chrome弃用消息是:


ArrayBuffer值在Blob构造器中不推荐使用。使用
ArrayBufferView。



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.

这篇关于blob不接受ios上的Uint8Array的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆