diff --git a/frontend/src/api/imageApi.ts b/frontend/src/api/imageApi.ts index aaa0aec..f3a21cc 100644 --- a/frontend/src/api/imageApi.ts +++ b/frontend/src/api/imageApi.ts @@ -31,7 +31,13 @@ export async function changeImageStatus( .then(({ data }) => data); } -export async function uploadImageFile(memberId: number, projectId: number, folderId: number, files: File[]) { +export async function uploadImageFile( + memberId: number, + projectId: number, + folderId: number, + files: File[], + processCallback: (progress: number) => void +) { const formData = new FormData(); files.forEach((file) => { formData.append('imageList', file); @@ -40,30 +46,60 @@ export async function uploadImageFile(memberId: number, projectId: number, folde return api .post(`/projects/${projectId}/folders/${folderId}/images/file`, formData, { params: { memberId }, + onUploadProgress: (progressEvent) => { + if (progressEvent.total) { + const progress = Math.round((progressEvent.loaded * 100) / progressEvent.total); + processCallback(progress); + } + }, }) .then(({ data }) => data); } -export async function uploadImageFolder(memberId: number, projectId: number, files: File[]) { +export async function uploadImageFolder( + memberId: number, + projectId: number, + folderId: number, + files: File[], + processCallback: (progress: number) => void +) { const formData = new FormData(); files.forEach((file) => { formData.append('imageList', file); }); return api - .post(`/projects/${projectId}/folders/${0}/images/file`, formData, { + .post(`/projects/${projectId}/folders/${folderId}/images/file`, formData, { params: { memberId }, + onUploadProgress: (progressEvent) => { + if (progressEvent.total) { + const progress = Math.round((progressEvent.loaded * 100) / progressEvent.total); + processCallback(progress); + } + }, }) .then(({ data }) => data); } -export async function uploadImageZip(memberId: number, projectId: number, file: File) { +export async function uploadImageZip( + memberId: number, + projectId: number, + folderId: number, + file: File, + processCallback: (progress: number) => void +) { const formData = new FormData(); formData.append('folderZip', file); return api - .post(`/projects/${projectId}/folders/${0}/images/zip`, formData, { + .post(`/projects/${projectId}/folders/${folderId}/images/zip`, formData, { params: { memberId }, + onUploadProgress: (progressEvent) => { + if (progressEvent.total) { + const progress = Math.round((progressEvent.loaded * 100) / progressEvent.total); + processCallback(progress); + } + }, }) .then(({ data }) => data); } diff --git a/frontend/src/components/ImageUploadFileModal/ImageUploadFileForm.tsx b/frontend/src/components/ImageUploadFileModal/ImageUploadFileForm.tsx index dd64af4..71c5569 100644 --- a/frontend/src/components/ImageUploadFileModal/ImageUploadFileForm.tsx +++ b/frontend/src/components/ImageUploadFileModal/ImageUploadFileForm.tsx @@ -22,6 +22,7 @@ export default function ImageUploadFileForm({ const [isUploading, setIsUploading] = useState(false); const [isUploaded, setIsUploaded] = useState(false); const [isFailed, setIsFailed] = useState(false); + const [progress, setProgress] = useState(0); const uploadImageFile = useUploadImageFileQuery(); @@ -71,6 +72,9 @@ export default function ImageUploadFileForm({ projectId, folderId, files, + progressCallback: (progress: number) => { + setProgress(progress); + }, }, { onSuccess: () => { @@ -115,11 +119,11 @@ export default function ImageUploadFileForm({ )} {files.length > 0 && ( -
    +
      {files.map((file, index) => (
    • {file.webkitRelativePath || file.name} {isUploading ? ( @@ -127,19 +131,19 @@ export default function ImageUploadFileForm({ {isUploaded ? ( ) : isFailed ? ( ) : ( )} @@ -171,7 +175,7 @@ export default function ImageUploadFileForm({ } disabled={!isUploaded && !isFailed} > - {isFailed ? '업로드 실패 (닫기)' : isUploaded ? '업로드 완료 (닫기)' : '업로드 중...'} + {isFailed ? '업로드 실패 (닫기)' : isUploaded ? '업로드 완료 (닫기)' : `업로드 중... ${progress}%`} ) : ( ) : ( ) : (