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

标签 javascript binary internet-explorer-9 base64 polyfills

我有以下实用程序:

        // 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/

相关文章:

C++ 将不同的数据类型打包到一个 long 变量中

c# - WebBrowser控件使用IE9

javascript - Node.js promise 链

javascript - Node js 调试在 Visual Studio 代码中不起作用(2020 年)

javascript - JS : Initialize & push to multi-dimensional array in a single line of code? 创建树结构

javascript - 如何从asp.cs方法中获取javascript中的数据

javascript - 有谁知道如何计算字符串中的字节数?

c - 如何从汇编代码运行 C 二进制文件?

javascript - IE 9 标准模式 : normalize() method does not work

css - IE9 DIV 填充问题