How to convert js base64 pictures to binary

because I want to send a picture to the app end, I have to send them a binary picture. I can"t even use Blob to solve the base64. How to transfer the base64 picture to the app end in binary form

Apr.22,2021

/**
 * base64urlBlob
 * @param urlData
 *        urlbase64
 */
function convertBase64UrlToBlob(urlData){
    var arr = urlData.split(','), mime = arr[0].match(/:(.*?);/)[1],
        bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
    while(n--){
        u8arr[n] = bstr.charCodeAt(n);
    }
    return new Blob([u8arr], {type:mime});
}

if you want to use the form, it is:

var formData = new FormData() ;
var blobDate = convertBase64UrlToBlob( base64 );
formData.append("file", blobDate); // 

Blob object is fine, isn't it?


has been solved. Just send base64. You don't have to convert to binary

.
Menu