【问题标题】:Blob constructor not working in safari / opera?Blob 构造函数在 Safari/Opera 中不起作用?
【发布时间】:2013-07-03 10:03:36
【问题描述】:

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

这是我的问题的简化版本: 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)

【问题讨论】:

标签: javascript


【解决方案1】:

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

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

它会起作用的。

【讨论】:

  • 如果您的视图是缓冲区的一部分怎么办?
  • 对我不起作用...我使用它没有第二个参数 {type: "image/png"}
  • 对我也不起作用。我正在使用 Safari 浏览器 5.1.7 并使用上述相同的 blob 示例。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-02-03
  • 2013-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多