-
Notifications
You must be signed in to change notification settings - Fork 5
Fix: 한글 파일 이미지 업로드 이슈 해결 / Refactor : form #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a8b3842
fix: 파일 업로드시 이름 변경
hongggyelim 034cc95
refactor: 이미지 업로드 함수 분리
hongggyelim 64a53e2
refactor: 임시저장 함수 분리
hongggyelim ade4536
chore: 임시저장 인수 추가
hongggyelim d432d7a
fix: 임시저장 로직 수정
hongggyelim ba9389e
chore: 코드 순서 수정
hongggyelim 31b9b49
Merge remote-tracking branch 'origin/dev' into refactor/form
hongggyelim 0c886e0
refactor: apply 임시저장 분리
hongggyelim 25f5cc3
fix: 커스텀 훅으로 변경
hongggyelim 64ded51
Merge branch 'dev' into refactor/form
cccwon2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { useUpdateProfile } from "@/hooks/queries/user/me/useUpdateProfile"; | ||
| import renameFile from "@/utils/renameFile"; | ||
| import toast from "react-hot-toast"; | ||
|
|
||
| const useUploadImages = () => { | ||
| const { uploadImageMutation } = useUpdateProfile(); | ||
|
|
||
| const uploadImages = async (files: File[]) => { | ||
| const uploadedUrls: string[] = []; | ||
|
|
||
| for (const file of files) { | ||
| const maxSize = 5 * 1024 * 1024; // 5MB | ||
| if (file.size > maxSize) { | ||
| toast.error(`5MB 이상의 파일은 업로드할 수 없습니다.`); | ||
| continue; | ||
| } | ||
|
|
||
| try { | ||
| const uploadResponse = await uploadImageMutation.mutateAsync(renameFile(file)); | ||
| if (uploadResponse?.url) { | ||
| uploadedUrls.push(uploadResponse.url); | ||
| } | ||
| } catch (uploadError) { | ||
| console.error(`파일 ${file.name} 업로드 실패:`, uploadError); | ||
| } | ||
| } | ||
|
|
||
| return uploadedUrls; | ||
| }; | ||
|
|
||
| return { uploadImages }; | ||
| }; | ||
|
|
||
| export default useUploadImages; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // 파일 이름을 임의의 값으로 수정하는 함수(한글 파일명 인코딩 방지) | ||
|
|
||
| const renameFile = (file: File) => { | ||
| const now = new Date(); | ||
| const timestamp = now.toISOString().replace(/[-:T]/g, "").slice(0, 14); | ||
| const fileExtension = file.name.split(".").pop(); // 확장자 추출 | ||
| const newFileName = `${timestamp}.${fileExtension}`; // 새로운 이름 생성 | ||
|
|
||
| const renamedFile = new File([file], newFileName, { type: file.type }); | ||
| return renamedFile; | ||
| }; | ||
| export default renameFile; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import toast from "react-hot-toast"; | ||
|
|
||
| // 폼데이터 임시 저장 함수 | ||
| const tempSave = async (name: string, data: any) => { | ||
| if (typeof window !== "undefined") { | ||
| window.localStorage.setItem(name, JSON.stringify(data)); | ||
| } | ||
| toast.success("임시 저장되었습니다."); | ||
| console.log("임시저장 데이터", data); | ||
| }; | ||
| export default tempSave; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import axios from "axios"; | ||
| import toast from "react-hot-toast"; | ||
|
|
||
| // 이력서 업로드 api -> id, name 반환 | ||
| const uploadResume = async (file: FileList) => { | ||
| const uploadedFile: { resumeName: string; resumeId: number } = { | ||
| resumeName: "", | ||
| resumeId: 0, | ||
| }; | ||
| const formData = new FormData(); | ||
| formData.append("file", file[0]); | ||
| try { | ||
| const response = await axios.post(`/api/resume/upload`, formData, { | ||
| headers: { | ||
| "Content-Type": "multipart/form-data", | ||
| }, | ||
| timeout: 5000, // 5초 타임아웃 설정 | ||
| }); | ||
| console.log("이력서 업로드", response.data); | ||
| return { | ||
| resumeName: response.data.resumeName, | ||
| resumeId: response.data.resumeId, | ||
| }; | ||
| } catch (error) { | ||
| console.error("Error uploading resume:", error); | ||
| toast.error("이력서 업로드에 실패했습니다."); | ||
| } | ||
| return uploadedFile; | ||
| }; | ||
|
|
||
| export default uploadResume; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 해결해주셨군요 ! 감사합니다 ~