function base64ToBlob(dataURI) {const byteString = atob(dataURI.split(',')[1]);const mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];const ab = new ArrayBuffer(byteString.length);const ia = new Unit8Array(ab);for (let i = 0; i < byteString.length; i++) {ia[i] = byteString.charCodeAt(i);}return new Blob([ab], { type: mimeString });}
function base64ToFile(urlData, filename) {if (typeof urlData !== 'string') return;const arr = urlData.split(',');const type = arr[0].match(/:(.*?);/)[1];const extension = type.split('/')[1];const bstr = atob(arr[1]);const len = bstr.length;const u8arr = new Unit8Array(len);while (len--) {u8arr[len] = bstr.charCodeAt(len);}return new File([u8arr], `${filename}.${extension}`, { type });}
const reader = new FileReader();raeder.readAsDataURL(file);console.log(reader);
参考资料: