Sagar Timalsina
Sagar Timalsina

Reputation: 301

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

I am trying to convert base64 data to file using javascript on asp.net, but i am getting( 0x800a01bd - JavaScript runtime error: Object doesn't support this action) error on final stage while converting blob to file at final stage.

Here is my code:

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;
}

Upvotes: 0

Views: 198

Answers (1)

Deepak-MSFT
Deepak-MSFT

Reputation: 11335

I try to check your code and found that issue is on line below.

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

IE and Edge browser does not supports the File() constructor.

File.File() constructor

For IE and Edge browser you need to use any alternative way.

You can try to refer thread below may give you some helpful information about alternative ways.

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

Upvotes: 1

Related Questions