Blob构造函数不在safari / opera中工作?

时间:2013-01-15 21:47:56

标签: javascript

我正在尝试从数组缓冲区构造一个Blob,原始来自二进制字符串。它在Firefox和Firefox中运行良好Chrome,但我不知道Safari&戏

这是我的问题的简化版本: http://plnkr.co/edit/sfEEHf?p=preview

// 1x1 red PNG pixle
base64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIW2P8z8DwHwAFBQIAHl6u2QAAAABJRU5ErkJggg==";
byteString = atob(base64);

// convert binary to array buff so we can construct a blob later
arrayBuffer = new ArrayBuffer(byteString.length);
intArray = new Uint8Array(arrayBuffer);

for (i = 0; i < byteString.length; i += 1) {
  intArray[i] = byteString.charCodeAt(i);
}

// construct blob
blob = new Blob([intArray], {type: "image/png"});
console.log(blob.size); // suppose to be 70 (its 19 in safari)

1 个答案:

答案 0 :(得分:11)

在Safari中,您需要使用TypedArray上的'buffer'属性,即:

blob = new Blob([intArray.buffer], {type: "image/png"});

它会起作用。