-
Notifications
You must be signed in to change notification settings - Fork 3
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
[BE] feat: s3를 프로젝트와 연동 #187
Conversation
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.
인프라 구축 쉽지 않았을텐데 고생 많았어요~!!
도도 덕분에 편하게 개발합니다 🙇♂️
backend/build.gradle
Outdated
swaggerUI 'org.webjars:swagger-ui:4.11.1' | ||
|
||
implementation "software.amazon.awssdk:s3:2.26.21" | ||
|
||
|
||
} |
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.
swaggerUI 'org.webjars:swagger-ui:4.11.1' | |
implementation "software.amazon.awssdk:s3:2.26.21" | |
} | |
swaggerUI 'org.webjars:swagger-ui:4.11.1' | |
implementation "software.amazon.awssdk:s3:2.26.21" | |
} |
public ImageController(FileStorageManager fileStorageManager) { | ||
this.fileStorageManager = fileStorageManager; | ||
} | ||
|
||
|
||
@PostMapping("/test-upload") | ||
public ResponseEntity<String> uploadFile(@RequestParam("file") MultipartFile file) { | ||
String imageUrl = fileStorageManager.uploadFile(file); | ||
return ResponseEntity.ok(imageUrl); | ||
} |
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.
public ImageController(FileStorageManager fileStorageManager) { | |
this.fileStorageManager = fileStorageManager; | |
} | |
@PostMapping("/test-upload") | |
public ResponseEntity<String> uploadFile(@RequestParam("file") MultipartFile file) { | |
String imageUrl = fileStorageManager.uploadFile(file); | |
return ResponseEntity.ok(imageUrl); | |
} | |
public ImageController(FileStorageManager fileStorageManager) { | |
this.fileStorageManager = fileStorageManager; | |
} | |
@PostMapping("/test-upload") | |
public ResponseEntity<String> uploadFile(@RequestParam("file") MultipartFile file) { | |
String imageUrl = fileStorageManager.uploadFile(file); | |
return ResponseEntity.ok(imageUrl); | |
} |
개행이 2줄이군요!!
예시 코드는 나중에 까먹지 않고 삭제할 수 있도록 TODO를 남겨도 좋을 것 같아요!
public interface FileStorageManager { | ||
|
||
public String uploadFile(MultipartFile file); | ||
} |
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.
인터페이스로 해결했군요 좋네요 👍
} | ||
|
||
public String uploadFile(MultipartFile file) { | ||
String key = file.getOriginalFilename(); | ||
|
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.
} | |
public String uploadFile(MultipartFile file) { | |
String key = file.getOriginalFilename(); | |
} | |
@Override | |
public String uploadFile(MultipartFile file) { | |
String key = file.getOriginalFilename(); | |
없어도 잘 되겠지만, 오버라이드는 명시해주는 게 좋은 것 같아요.
} catch (Exception e) { | ||
throw new FriendoglyException("MultipartFile의 임시 파일 생성 중 에러 발생"); | ||
} |
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.
이 부분은 상태코드가 400이랑은 다르게 관리되겠네요!
FriendoglyException
에 상태코드를 지정할 수 있는 생성자가 있어요.
public interface FileStorageManager { | ||
|
||
public String uploadFile(MultipartFile file); | ||
} |
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.
public interface FileStorageManager { | |
public String uploadFile(MultipartFile file); | |
} | |
public interface FileStorageManager { | |
String uploadFile(MultipartFile file); | |
} |
try (FileOutputStream fos = new FileOutputStream(file)) { | ||
fos.write(multipartFile.getBytes()); | ||
fos.flush(); | ||
} catch (Exception e) { | ||
throw new FriendoglyException("MultipartFile to File 변환 중 오류 발생"); | ||
} |
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.
try (FileOutputStream fos = new FileOutputStream(file)) { | |
fos.write(multipartFile.getBytes()); | |
fos.flush(); | |
} catch (Exception e) { | |
throw new FriendoglyException("MultipartFile to File 변환 중 오류 발생"); | |
} | |
try (FileOutputStream fos = new FileOutputStream(file)) { | |
fos.write(multipartFile.getBytes()); | |
fos.flush(); | |
} catch (IOException e) { | |
throw new FriendoglyException("MultipartFile to File 변환 중 오류 발생"); | |
} |
@Value("${aws.s3.bucket-name}") | ||
private String BUCKET_NAME; | ||
|
||
@Value("${aws.s3.server.endpoint}") | ||
private String S3_ENDPOINT; | ||
|
||
@Value("${aws.s3.server.key-prefix}") | ||
private String KEY_PREFIX; |
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.
환경변수도 생성자 주입을 사용할 수 있다는 사실을 알고계신가요? (두둥)
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.
알고있어요! 근데 그거는 final을 붙여서 불변성을 유지하기 위함인가요?
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.
고생하셨어요~~!
이슈
개발 사항
리뷰 요청 사항 (없으면 삭제해 주세요)
전달 사항 (없으면 삭제해 주세요)