0

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;
}
3
  • Does this answer your question? How to convert Base64 String to javascript file object like as from file input form? Commented Dec 3, 2019 at 4:24
  • No, I am getting same error '0x800a01bd - JavaScript runtime error: Object doesn't support this action' also with this solution. Commented Dec 3, 2019 at 4:35
  • var block = strL.split(";"); // Get the content type of the image var type = block[0].split(":")[1];// In this case "image/gif" // you can al so assign // var type = 'base64'; var pos = str.replace('data:;base64,', ''); Commented Dec 3, 2019 at 4:58

1 Answer 1

1

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?

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.