From e54d936b199f61e0765c4b253a21b0f696104284 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Fri, 1 May 2026 11:24:22 +0700 Subject: [PATCH] fix: test load file iOS Safari --- .../01_Information/02_ChangeName.vue | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/modules/10_registry/01_Information/02_ChangeName.vue b/src/modules/10_registry/01_Information/02_ChangeName.vue index 7d8074f..dc2b645 100644 --- a/src/modules/10_registry/01_Information/02_ChangeName.vue +++ b/src/modules/10_registry/01_Information/02_ChangeName.vue @@ -139,10 +139,38 @@ async function onDownloadFile(id: string, profileId: string) { const downloadUrl = res.data.downloadUrl; const response = await fetch(downloadUrl); const blob = await response.blob(); - const url = URL.createObjectURL(blob); + + const contentType: string | null = response.headers.get("Content-Type"); + + // 2. สร้างตัวแปลง MIME Type เป็นนามสกุลไฟล์ + const extensionMap: Record = { + "application/pdf": "pdf", + "image/jpeg": "jpg", + "image/png": "png", + "image/gif": "gif", + "application/zip": "zip", + "application/vnd.openxmlformats-officedocument.wordprocessingml.document": + "docx", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": + "xlsx", + }; + + let extension = contentType ? extensionMap[contentType] : undefined; + + if (!extension) { + const urlWithoutQuery = downloadUrl.split("?")[0]; + extension = urlWithoutQuery.includes(".") + ? urlWithoutQuery.split(".").pop() + : "pdf"; + } + + const blobForDownload = new Blob([blob], { + type: "application/octet-stream", + }); + const url = URL.createObjectURL(blobForDownload); const link = document.createElement("a"); link.href = url; - link.download = `ประวัติการเปลี่ยนชื่อ-นามสกุล_`; + link.download = `ประวัติการเปลี่ยนชื่อ-นามสกุล.${extension}`; document.body.appendChild(link); link.click(); setTimeout(() => {