gpt4 book ai didi

javascript - IE9 - DataURI 到二进制 - .atob、Uint8Array 和 ArrayBuffer 的 Polyfills - 数组对于 polyfill 来说太大

转载 作者:行者123 更新时间:2023-11-30 05:31:43 30 4
gpt4 key购买 nike

我有以下实用程序:

        // Utility function to remove base64 URL prefix and store base64-encoded string in a    Uint8Array
// Courtesy: https://gist.github.com/borismus/1032746
function convertDataURIToBinary(dataURI) {
var BASE64_MARKER = ';base64,';
var base64Index = dataURI.indexOf(BASE64_MARKER) + BASE64_MARKER.length;
var base64 = dataURI.substring(base64Index);
var raw = window.atob(base64);
var rawLength = raw.length;
var array = new Uint8Array(new ArrayBuffer(rawLength));

for (i = 0; i < rawLength; i++) {
array[i] = raw.charCodeAt(i);
}
return array;
}

我是这样使用的:

        // Read the binary contents of the base 64 data URL into a Uint8Array
// Append the contents of this array to the SP.FileCreationInformation
var arr = convertDataURIToBinary(convertedDataURI);
for (var i = 0; i < arr.length; ++i) {
fileCreateInfo.get_content().append(arr[i]);
}

准备文件上传。

为了让它在 IE9 中工作,我使用了以下 polyfills:

现在我在创建 Uint8Array 时得到了一个非常有用的异常:

SCRIPT5022: Exception thrown and not caught

经过一些调试我发现了问题:

if (obj.length > MAX_ARRAY_LENGTH) throw RangeError('Array too large for polyfill');

我的对象的长度1085798MAX_ARRAY_LENGTH 等于100000。我可以更改此值,但我想这是有原因的。

有人知道更好的方法吗?

最佳答案

好吧,我得到了答案。

我刚刚设置

MAX_ARRAY_LENGTH = 2000000; //value that is higher than the expected array.length (may I should just remove the check)

结果是,浏览器由于大数组而卡住,但几秒(也许更多)后它解冻并完成上传。

MAX_ARRAY_LENGTH 用于在使用时保持一定的速度。

关于javascript - IE9 - DataURI 到二进制 - .atob、Uint8Array 和 ArrayBuffer 的 Polyfills - 数组对于 polyfill 来说太大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26524026/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com