파일업로드 도침
iipbs_sn / build (push) Waiting to run

This commit is contained in:
yschoi
2025-05-22 11:32:13 +09:00
parent bf4d1c5bcc
commit ab00dc1e86
3 changed files with 19 additions and 2 deletions
@@ -51,4 +51,6 @@ export const handleUpload = (files: FileList, options?: UploadOptions) => {
upload.start();
options?.handleUploadStart?.(upload);
console.log("upload start");
};
+16 -1
View File
@@ -8,6 +8,16 @@ import { handleUpload } from "@utils";
const FileUploadForm = ({ title, onSubmit }: { title: string, onSubmit:(files:FileList, year:string, quarter:string) => void }) => {
const handleUploadResponse = (file: File) => async (res: HttpResponse) => {
const fileInfo = res.getHeader("X-File-Info");
if (!fileInfo) return;
const { atflCd, atflId } = JSON.parse(fileInfo) ?? {};
const orgnlFileNm = file.name;
console.log(atflCd, atflId, orgnlFileNm);
};
// 현재 년도부터 10년 전까지의 년도 옵션 생성
const yearOptions = Array.from({ length: 10 }, (_, i) => {
const year = new Date().getFullYear() - i;
@@ -17,6 +27,8 @@ const FileUploadForm = ({ title, onSubmit }: { title: string, onSubmit:(files:Fi
const [files, setFiles] = useState<FileList | null>(null);
const [selectedYear, setSelectedYear] = useState<string>(yearOptions[0]?.val || '');
const [selectedQuarter, setSelectedQuarter] = useState<string>(quater[0]?.val || '');
const [upload, setUpload] = useState<Upload | null>(null);
return (
<div>
<div className='card-header'>
@@ -49,7 +61,9 @@ const FileUploadForm = ({ title, onSubmit }: { title: string, onSubmit:(files:Fi
if (!selectedFiles) return;
const fileArray = Array.from(selectedFiles);
setFiles(fileArray);
if(!fileArray){
setFiles(fileArray);
}
if (fileArray[0]) {
handleUpload(selectedFiles, {
handleUploadStart: setUpload,
@@ -57,6 +71,7 @@ const FileUploadForm = ({ title, onSubmit }: { title: string, onSubmit:(files:Fi
handleResponse: handleUploadResponse(fileArray[0]),
});
}
}}
customPreview={<></>}
/>
+1 -1
View File
@@ -26,7 +26,7 @@ const Page = () => {
alert('파일을 선택해주세요')
}
// TODO: 추후 파일코드 동적으로 세팅
handleDownload('/sn/attach-service/api/v1/download/6066b08c-2a55-438c-b8ff-2aed9739a0c6', fileNm)
handleDownload('/attach-service/api/v1/download/6066b08c-2a55-438c-b8ff-2aed9739a0c6', fileNm)
}
//TODO: 파일 업로드 처리
return (