-
Notifications
You must be signed in to change notification settings - Fork 1
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
Presigned URL 활용한 업로드 #142
Conversation
* GET 요청 : /upload params: path, fileName, ext * 다만 업로드 된 파일의 접근 권한을 바꿔줘야 하는데, 아직까진 마땅한 방법을 찾지 못함 (Object Storage에서 현재는 수동으로 파일 권한 열어 링크에 접근할 수 있도록 함)
* 세 개의 경로 (image/user/아이디, image/music/아이디, music/아이디)에 맞는 정규표현식 추가해서 검사
타입, 음악제목을 클라이언트에게 받고 서버에서 path를 설정해 넘겨줘야 할 듯 |
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.
path의 musicId, userId 를 클라이언트에서 넘겨주는 게 조금 어색한 것 같아요
* 기존에 musicId를 경로에 넣는 로직은 말이 안되어 클라이언트에게 uuid(musicId)를 넘겨줌 * /upload/uuid 를 추가해 uuid를 반환
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.
코드 다 좋은 것 같아요! NCP 쪽 권한 문제나 인프라는 더 같이 고민해봐야 할 것 같아요
}) | ||
.promise(); | ||
private isValidFlag(flag: string): boolean { | ||
if (keyFlags.includes(flag)) return true; |
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.
상수 관리하는 거 좋은 것 같아요! 👍
user: (uuid) => `image/user/${uuid}/user.png`, | ||
music: (uuid) => `music/${uuid}/music.mp3`, | ||
cover: (uuid) => `image/cover/${uuid}/cover.png`, | ||
}; |
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.
이렇게 관리하는 거 좋은 것 같아요 👍
Issue
Overview
/upload?path=아래 세 개의 경로 중 하나형태&fileName=파일이름&ext=확장자
로 요청(GET)=> Presigned URL 반환
=> 이후 URL에 PUT 요청(binary 형태의 file)을 보내면 업로드 성공!
** 바뀐 로직
2-1. 클라에서 음악 업로드를 하고 싶으면 {type: music, uuid: uuid} 로 요청을 보냄 → 서버에서 /music/{uuid}/music.mp3 의 presigned url 을 응답 → 클라이언트에서 해당 url 로 음악 업로드
2-2. 음악 cover(사진) 업로드를 하고 싶으면 {type: cover, uuid: uuid} 로 요청을 보냄 → 서버에서 /image/cover/{uuid}/cover.png 의 presigned url 응답 → 클라이언트에서 해당 url 로 커버 사진 업로드
Screenshot
음악/이미지 업로드
![image](https://private-user-images.githubusercontent.com/83707411/284887169-9ea7f370-d4f2-42ad-9bda-9370be516bf6.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5ODEzMTYsIm5iZiI6MTczODk4MTAxNiwicGF0aCI6Ii84MzcwNzQxMS8yODQ4ODcxNjktOWVhN2YzNzAtZDRmMi00MmFkLTliZGEtOTM3MGJlNTE2YmY2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA4VDAyMTY1NlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTM4MzM2YzFiYWQ4ZWRiNGM1N2M4YjVhOGQyODIxZjYyZThjMzMxN2Y5ODk2ZTY1OGM5MTQzNTI4MjI5NGY0NzUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.vCaHjitPnbBPWkqxfRcJKqT0OsL-unoXeH87JIJ7a1s)
잘못된 uuid 입력 시
![image](https://private-user-images.githubusercontent.com/83707411/284887056-f74068a2-2b04-41ce-8aa7-1b85b5dbadae.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5ODEzMTYsIm5iZiI6MTczODk4MTAxNiwicGF0aCI6Ii84MzcwNzQxMS8yODQ4ODcwNTYtZjc0MDY4YTItMmIwNC00MWNlLThhYTctMWI4NWI1ZGJhZGFlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA4VDAyMTY1NlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTQwYjU0YWMzZjliZDQ5MWQ0YmRlZTE3MzU2OGRhMzgxNzZlNzRhZTkyYTc4N2MwZmQ4NDU0NDIwNGM2YmMzZWUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.WF3wt7OQvqLt_Pavttan6JoKDs4-r-ILMIrsI8DKtI8)
user 정보 없을 시
![image](https://private-user-images.githubusercontent.com/83707411/284887270-b67c5bfb-8b8e-429f-a3e6-c1eaf5918c0f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5ODEzMTYsIm5iZiI6MTczODk4MTAxNiwicGF0aCI6Ii84MzcwNzQxMS8yODQ4ODcyNzAtYjY3YzViZmItOGI4ZS00MjlmLWEzZTYtYzFlYWY1OTE4YzBmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA4VDAyMTY1NlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWZmYThmNTA5MDM2NDU5YjA3MDYxY2JlNDVlNjNmZDNjZmYwNjExNGZhNjkxZDE5YmI5MzUzMzQxODliYzQ1MDQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.P0HJTTZlhG_rx-N_l8xqe3xR_0iSeMXMj9q1aQdJxwg)