javascript - 在 Internet Explorer 上使用 JavaScript 将 Base64 数据转换为文件时出错(0x800a01bd - JavaScript 运行时错误 : Object doesn't support this action)

标签 javascript asp.net internet-explorer

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

这是我的代码:

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 浏览器,您需要使用任何替代方式。

您可以尝试引用下面的帖子,可能会为您提供一些有关替代方法的有用信息。

Is there an alternative for File() constructor for Safari and IE?

关于javascript - 在 Internet Explorer 上使用 JavaScript 将 Base64 数据转换为文件时出错(0x800a01bd - JavaScript 运行时错误 : Object doesn't support this action),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59150147/

相关文章:

javascript - 如何通过 Jquery 和 ajax 从响应中下载 JSON 文件

javascript - Array.from 与新 Set

c# - 如何从 ASP.NET Web 服务返回原始字节?

javascript - 从 Sencha Touch 2 读取 Asp.net 中的 POST 参数

Javascript:模拟 IE 中图像的 maxWidth 和 maxHeight

javascript - html 标签在 Javascript 中不起作用

javascript - 获取Keycloak中登录用户的角色

c# - 如何使用 Asp.Net Web API 将对象设置为 JSON 字符串中的值?

javascript - 如何修复 Internet Explorer 8 中的 `Internet Argument Code: 0`?

javascript - 有没有办法使用 html、javascript 或 flash 在 IE 中关闭 url "cliking"声音?