260928_01_ENH: 신청서 파일 업로드/다운로드 추가

This commit is contained in:
2026-09-28 15:40:08 +09:00
parent 17c34d76b9
commit 2647b88daf
5 changed files with 168 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
import {downloadFile} from "@kri/common/browser";
import {HttpError} from "@kri/common/http";
const trimDispositionValue = (value: string) => value.trim().replace(/^"|"$/g, "");
@@ -41,6 +42,22 @@ export const downloadExcelBuffer = (buffer: ArrayBuffer, fileName: string) => {
downloadBlob(buffer, fileName, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
};
/*
* 다운로드 API를 raw fetch로 호출해 Blob으로 저장한다.
* expectBinary 경로는 응답 헤더를 버리므로, 첨부파일 이름은 여기서 Content-Disposition으로 결정한다.
* 파일이 없으면 API가 404를 반환하며 HttpError로 전파한다.
*/
export const downloadFromApiUrl = async (url: string, fallbackFileName = "download") => {
const response = await fetch(url, {cache: "no-store"});
if (!response.ok) {
const data = await response.json().catch(() => null);
throw new HttpError(response.status, data, response.url, response.headers);
}
const blob = await response.blob();
const fileName = getFileNameFromContentDisposition(response.headers.get("content-disposition")) ?? fallbackFileName;
downloadFile(blob, fileName);
};
export const downloadFromUrl = (url: string) => {
const link = document.createElement("a");
link.href = url;