Merge branch 'develop' into dev
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m18s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m18s
This commit is contained in:
commit
6ad798a2a2
1 changed files with 30 additions and 2 deletions
|
|
@ -139,10 +139,38 @@ async function onDownloadFile(id: string, profileId: string) {
|
||||||
const downloadUrl = res.data.downloadUrl;
|
const downloadUrl = res.data.downloadUrl;
|
||||||
const response = await fetch(downloadUrl);
|
const response = await fetch(downloadUrl);
|
||||||
const blob = await response.blob();
|
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<string, string> = {
|
||||||
|
"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");
|
const link = document.createElement("a");
|
||||||
link.href = url;
|
link.href = url;
|
||||||
link.download = `ประวัติการเปลี่ยนชื่อ-นามสกุล_`;
|
link.download = `ประวัติการเปลี่ยนชื่อ-นามสกุล.${extension}`;
|
||||||
document.body.appendChild(link);
|
document.body.appendChild(link);
|
||||||
link.click();
|
link.click();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue