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

[BE] feat: s3를 프로젝트와 연동 #187

Merged
merged 30 commits into from
Jul 24, 2024
Merged

[BE] feat: s3를 프로젝트와 연동 #187

merged 30 commits into from
Jul 24, 2024

Conversation

ehtjsv2
Copy link
Contributor

@ehtjsv2 ehtjsv2 commented Jul 24, 2024

이슈

개발 사항

  • S3 이미지 업로드 기능 구현
  • StorageManager Interface구현
  • 서버(EC2), Local 구현체 달라지게 구현

리뷰 요청 사항 (없으면 삭제해 주세요)

  • 컨벤션 잘 지켰는 지 확인해주세요..production 코드 pr은 처음이라..

전달 사항 (없으면 삭제해 주세요)

  • ImageController는 Image upload잘 되는 지 확인을 위한 컨트롤러인데, 배포환경에서도 테스트할 일 있을 것 같아서 남겨둘게요~!
  • content type JPG만 되어있는데 파일에 따라 달라지도록 고쳐야됨
    • 따로 이슈파서 해결할게요~!

@ehtjsv2 ehtjsv2 linked an issue Jul 24, 2024 that may be closed by this pull request
@ehtjsv2 ehtjsv2 self-assigned this Jul 24, 2024
Copy link

github-actions bot commented Jul 24, 2024

Unit Test Results

92 tests   92 ✔️  6s ⏱️
20 suites    0 💤
20 files      0

Results for commit 283904b.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@takoyakimchi takoyakimchi left a comment

Choose a reason for hiding this comment

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

인프라 구축 쉽지 않았을텐데 고생 많았어요~!!
도도 덕분에 편하게 개발합니다 🙇‍♂️

Comment on lines 67 to 72
swaggerUI 'org.webjars:swagger-ui:4.11.1'

implementation "software.amazon.awssdk:s3:2.26.21"


}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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"
}

Comment on lines 15 to 24
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);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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를 남겨도 좋을 것 같아요!

Comment on lines 5 to 8
public interface FileStorageManager {

public String uploadFile(MultipartFile file);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

인터페이스로 해결했군요 좋네요 👍

Comment on lines 37 to 41
}

public String uploadFile(MultipartFile file) {
String key = file.getOriginalFilename();

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
}
public String uploadFile(MultipartFile file) {
String key = file.getOriginalFilename();
}
@Override
public String uploadFile(MultipartFile file) {
String key = file.getOriginalFilename();

없어도 잘 되겠지만, 오버라이드는 명시해주는 게 좋은 것 같아요.

Comment on lines 56 to 58
} catch (Exception e) {
throw new FriendoglyException("MultipartFile의 임시 파일 생성 중 에러 발생");
}
Copy link
Contributor

@takoyakimchi takoyakimchi Jul 24, 2024

Choose a reason for hiding this comment

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

이 부분은 상태코드가 400이랑은 다르게 관리되겠네요!
FriendoglyException에 상태코드를 지정할 수 있는 생성자가 있어요.

takoyakimchi
takoyakimchi previously approved these changes Jul 24, 2024
Comment on lines 5 to 8
public interface FileStorageManager {

public String uploadFile(MultipartFile file);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public interface FileStorageManager {
public String uploadFile(MultipartFile file);
}
public interface FileStorageManager {
String uploadFile(MultipartFile file);
}

Comment on lines 60 to 65
try (FileOutputStream fos = new FileOutputStream(file)) {
fos.write(multipartFile.getBytes());
fos.flush();
} catch (Exception e) {
throw new FriendoglyException("MultipartFile to File 변환 중 오류 발생");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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 변환 중 오류 발생");
}

J-I-H-O
J-I-H-O previously approved these changes Jul 24, 2024
Comment on lines +20 to +27
@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;
Copy link
Contributor

@J-I-H-O J-I-H-O Jul 24, 2024

Choose a reason for hiding this comment

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

환경변수도 생성자 주입을 사용할 수 있다는 사실을 알고계신가요? (두둥)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

알고있어요! 근데 그거는 final을 붙여서 불변성을 유지하기 위함인가요?

@ehtjsv2 ehtjsv2 changed the title [BE] feat: s3 프로젝트와 연동 [BE] feat: s3를 프로젝트와 연동 Jul 24, 2024
@ehtjsv2 ehtjsv2 dismissed stale reviews from J-I-H-O and takoyakimchi via 283904b July 24, 2024 03:06
Copy link
Contributor

@takoyakimchi takoyakimchi left a comment

Choose a reason for hiding this comment

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

고생하셨어요~~!

@ehtjsv2 ehtjsv2 merged commit 0a9473f into develop Jul 24, 2024
3 checks passed
@ehtjsv2 ehtjsv2 deleted the feat/s3_connection branch July 24, 2024 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

S3 사진 저장 기능 구현
3 participants