优化base642File

master
LiuJiaNan 2025-11-18 14:05:04 +08:00
parent 1bba9c9b7e
commit b43f6f54c9
1 changed files with 3 additions and 2 deletions

View File

@ -64,9 +64,10 @@ export function image2Base642(file) {
/**
base64转File对象
*/
export function base642File(base64, filename = "file") {
export function base642File(base64, filename = 'file') {
const arr = base64.split(",");
const mime = arr[0].match(/:(.*?);/)[1];
const ext = mime.split('/')[1];
const bstr = atob(arr[1]);
let n = bstr.length;
const u8arr = new Uint8Array(n);
@ -75,7 +76,7 @@ export function base642File(base64, filename = "file") {
u8arr[n] = bstr.charCodeAt(n);
}
return new File([u8arr], filename, { type: mime });
return new File([u8arr], `${filename}.${ext}`, { type: mime });
}
/**