Convert base64 image to Image File | JS
Copy Below Code
View As A Text File
Show Text Only
Show API
Edit Code
function dataURLtoFile(dataurl: any, filename: any) {
const arr = dataurl.split(",");
const mime = arr[0].match(/:(.*?);/)[1];
const bstr = atob(arr[1]);
let n = bstr.length;
const u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new File([u8arr], filename, { type: mime });
}
dataURLtoFile(imageSrc, "WebCamImage.jpeg")