优化base642File
parent
1bba9c9b7e
commit
b43f6f54c9
|
|
@ -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 });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue