场景
2023年03月23日
一、Base64 To Blob
function dataUrlToBlob(base64, mimeType) {
const reg = /^data:(.*);base64.*/;
mimeType = mimeType || reg.exec(base64)?.[1] || "";
let bytes = window.atob(base64.split(",")[1]);
let ab = new ArrayBuffer(bytes.length);
let ia = new Uint8Array(ab);
for (let i = 0; i < bytes.length; i++) {
ia[i] = bytes.charCodeAt(i);
}
return new Blob([ab], { type: mimeType });
}