Skip to content
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

Merged
merged 6 commits into from
Nov 22, 2023
Merged

Presigned URL 활용한 업로드 #142

merged 6 commits into from
Nov 22, 2023

Conversation

sk000801
Copy link
Member

@sk000801 sk000801 commented Nov 21, 2023

Issue

Overview

  • 클라이언트가 /upload?path=아래 세 개의 경로 중 하나형태&fileName=파일이름&ext=확장자 로 요청(GET)
    => Presigned URL 반환
    => 이후 URL에 PUT 요청(binary 형태의 file)을 보내면 업로드 성공!

** 바뀐 로직

  1. 업로드 화면으로 들어갈 때 서버에 한 번 요청을 보냄 → 서버는 uuid 값을 반환
    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 로 커버 사진 업로드
  • 다만 문제가 많습니다 🥲 (코드를 짜는게 아니라 생각하느라 오래 걸린 것 같네요ㅠㅠ)
  1. 버킷 비공개 전환 시 추가해야 하는 인증 헤더 코드가 잘 작동되지 않아 현재 버킷은 매우 public한 상태
  2. 같은 경로의 중복된 이름은 최근 파일로 덮어씌워집니다....

Screenshot

  • 음악/이미지 업로드
    image

  • 잘못된 uuid 입력 시
    image

  • user 정보 없을 시
    image

image

* GET 요청 : /upload
params: path, fileName, ext

* 다만 업로드 된 파일의 접근 권한을 바꿔줘야 하는데, 아직까진 마땅한 방법을 찾지 못함 (Object Storage에서 현재는 수동으로 파일 권한 열어 링크에 접근할 수 있도록 함)
* 세 개의 경로 (image/user/아이디, image/music/아이디, music/아이디)에 맞는 정규표현식 추가해서 검사
@sk000801 sk000801 added ✨ feat 기능 개발 🖥 server server labels Nov 21, 2023
@sk000801 sk000801 added this to the 🆙 upload milestone Nov 21, 2023
@sk000801 sk000801 self-assigned this Nov 21, 2023
@sk000801 sk000801 requested a review from khw3754 as a code owner November 21, 2023 08:49
@sk000801
Copy link
Member Author

타입, 음악제목을 클라이언트에게 받고 서버에서 path를 설정해 넘겨줘야 할 듯

Copy link
Collaborator

@khw3754 khw3754 left a 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를 반환
Copy link
Collaborator

@khw3754 khw3754 left a 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;
Copy link
Collaborator

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`,
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 관리하는 거 좋은 것 같아요 👍

@sk000801 sk000801 merged commit 477325f into develop Nov 22, 2023
1 check passed
@sk000801 sk000801 deleted the server/feat/124 branch November 22, 2023 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ feat 기능 개발 🖥 server server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants