From b43f6f54c9bff9bcc626563b903a5f027d6528b2 Mon Sep 17 00:00:00 2001 From: LiuJiaNan <15703339975@163.com> Date: Tue, 18 Nov 2025 14:05:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96base642File?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 }); } /**