Error Converting Base64 data to File using JavaScript on Internet Explorer(0x800a01bd - JavaScript runtime error: Object doesn't support this action)

Error Converting Base64 data to File using JavaScript on Internet Explorer(0x800a01bd - JavaScript runtime error: Object doesn't support this action)

我正在尝试在 asp.net 上使用 javascript 将 base64 数据转换为文件,但我收到(0x800a01bd - JavaScript 运行时错误:对象不支持此操作)在最后阶段将 blob 转换为文件时在最后阶段出错。

这是我的代码:

function dataBaseURLtoFile(str) {
    // extract content type and base64 payload from original string
    var pos = str.indexOf(';base64,');
    var type = str.substring(5, pos);
    var b64 = str.substr(pos + 8);

    // decode base64
    var imageContent = atob(b64);

    // create an ArrayBuffer and a view (as unsigned 8-bit)
    var buffer = new ArrayBuffer(imageContent.length);
    var view = new Uint8Array(buffer);

    // fill the view, using the decoded base64
    for (var n = 0; n < imageContent.length; n++) {
        view[n] = imageContent.charCodeAt(n);
    }

    // convert ArrayBuffer to Blob
    var blob = new Blob([buffer], { type: type });

    //convert blob to file

    var file = new File([blob], "name", { type: "image/jpeg", });

    return file;
}

我尝试检查您的代码,发现问题出在下面一行。

 var file = new File([blob], "name", { type: "image/jpeg", });

IE 和 Edge 浏览器不支持 File() 构造函数。

File.File() constructor

对于 IE 和 Edge 浏览器,您需要使用任何替代方式。

您可以尝试参考下面的线程,它可能会为您提供一些有关替代方法的有用信息。