Base64 string to blob object error

the base64-encoded image is returned in the background, but I need to convert it to url before I can use it, so I need to convert base64 to blob object first, and then convert it to url using url method. But when base64 is converted to blob object, many methods are tried to report an error, as shown in the following figure:
clipboard.png
what is the situation, my code:

function b64toBlob(dataURI) {
    var byteString = atob(dataURI.split(",")[1]);
    var ab = new ArrayBuffer(byteString.length);
    var ia = new Uint8Array(ab);

    for (var i = 0; i < byteString.length; iPP) {
        ia[i] = byteString.charCodeAt(i);
    }
    return new Blob([ab], { type: "image/jpeg" });
}
var b= b64toBlob(a.base64);//a{"name":"2.jpg","base64":"(base64)"}

solve!

Mar.06,2021

suspects that there is something wrong with your a.base64 itself. Can you type log to intercept the front part of the dataURI?


byteString

it's OK to get rid of the last two, but I don't know why. I'm going to send a question.

Menu