-
Notifications
You must be signed in to change notification settings - Fork 2
feat: 파일 단건 업로드 구현 #227
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
feat: 파일 단건 업로드 구현 #227
Changes from all commits
64a1b06
07686c0
bac0acb
84f332b
fe8244c
77df578
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,19 @@ | ||
| package in.koreatech.koin.global.domain.upload.controller; | ||
|
|
||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.MediaType; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestPart; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import org.springframework.web.multipart.MultipartFile; | ||
|
|
||
| import in.koreatech.koin.domain.user.model.UserType; | ||
| import static in.koreatech.koin.domain.user.model.UserType.OWNER; | ||
| import static in.koreatech.koin.domain.user.model.UserType.STUDENT; | ||
| import in.koreatech.koin.global.auth.Auth; | ||
| import in.koreatech.koin.global.domain.upload.dto.UploadFileResponse; | ||
| import in.koreatech.koin.global.domain.upload.dto.UploadUrlRequest; | ||
| import in.koreatech.koin.global.domain.upload.dto.UploadUrlResponse; | ||
| import in.koreatech.koin.global.domain.upload.model.ImageUploadDomain; | ||
|
|
@@ -26,9 +31,23 @@ public class UploadController implements UploadApi { | |
| public ResponseEntity<UploadUrlResponse> getPresignedUrl( | ||
| @PathVariable ImageUploadDomain domain, | ||
| @RequestBody @Valid UploadUrlRequest request, | ||
| @Auth(permit = {UserType.OWNER, STUDENT}) Long memberId | ||
| @Auth(permit = {OWNER, STUDENT}) Long memberId | ||
| ) { | ||
| var response = uploadService.getPresignedUrl(domain, request); | ||
| return ResponseEntity.ok(response); | ||
| } | ||
|
|
||
| @PostMapping( | ||
| value = "/{domain}/upload/file", | ||
| consumes = MediaType.MULTIPART_FORM_DATA_VALUE, | ||
| produces = MediaType.APPLICATION_JSON_VALUE | ||
|
Comment on lines
+42
to
+43
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A각각 클라이언트, 서버가 보내는 값의 타입을 정의한다고 이해했는데 다른 메서드들과 달리 해당 메서드에만 잇는 이유가 있을까요?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. swagger에 표현이 안되는 이슈가 있어서 MULTIPART_FORM_DATA를 다루는 값에 대해서 선언해줬습니다 |
||
| ) | ||
| public ResponseEntity<UploadFileResponse> uploadFile( | ||
| @PathVariable ImageUploadDomain domain, | ||
| @RequestPart MultipartFile multipartFile, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C스프링3에서는 xml을 이용해서 최대 파일 크기를 제한하였는데, 적용해보면 어떨까요?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test propreties에 적용해서 추가했습니다~ |
||
| @Auth(permit = {OWNER, STUDENT}) Long memberId | ||
| ) { | ||
| var response = uploadService.uploadFile(domain, multipartFile); | ||
| return new ResponseEntity<>(response, HttpStatus.CREATED); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package in.koreatech.koin.global.domain.upload.dto; | ||
|
|
||
| import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; | ||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
|
|
||
| @JsonNaming(value = SnakeCaseStrategy.class) | ||
| public record UploadFileResponse( | ||
| @Schema(description = "첨부 파일 URL", example = "https://static.koreatech.in/1.png") | ||
| String fileUrl | ||
| ) { | ||
|
|
||
| } |
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.
A
설정 파일에 담긴 정보를
@Value로 가져올 때 생성자를 통해 가져오는 이유가 있는 건가요??필드를 final로 유지하여 강건성을 높이기 위해서라고 봐도 될까요??
JwtProvider 등은 필드에서 주입받고 있는데 서로 다른 용도인 것인지 궁금합니다.
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.
강건성 높이려고 맞습니다~
다른 애들 필드주입이였군요 -_- 확인하고 수정할게요