diff --git a/utils/index.js b/utils/index.js index bfc6421..22dcee6 100644 --- a/utils/index.js +++ b/utils/index.js @@ -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 }); } /**