export function base64ToFile(imgBase64, fileName = "base64.png") {
const base64ToBlob = function(base64Data) {
let arr = base64Data.split(","),
fileType = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]),
l = bstr.length,
u8Arr = new Uint8Array(l);
while (l--) {
u8Arr[l] = bstr.charCodeAt(l);
}
return new Blob([u8Arr], {
type: fileType
});
};
const blobToFile = function(newBlob, fileName) {
newBlob.lastModifiedDate = new Date();
newBlob.name = fileName;
const files = new window.File([newBlob], fileName);
return files;
};
return blobToFile(base64ToBlob(imgBase64), fileName);
}