dataURLtoBlob(dataurl: string) {
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 Blob([u8arr], {
type: mime
});
}
dataURLtoFile(dataurl: string, filename: string) {
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 });
}
downloadBlob(blob: any, fileName: string) {
const a = document.createElement("a");
a.href = URL.createObjectURL(blob);
a.download = fileName;
a.click();
URL.revokeObjectURL(a.href);
a.remove();
}
fileToBase64(file: UploadFile, success: (base64: string, e: any) => void) {
const reader = new FileReader()
reader.readAsDataURL(file as any)
reader.onloadend = (e: any) => {
const base64 = e.target.result
success(base64, e)
}
}