Skip to content

Commit

Permalink
[BE] hotfix: image 문자열 자르기 에러 수정 (#604)
Browse files Browse the repository at this point in the history
* fix: s3 path 를 file full path 로 수정

* fix: 파일 확장자 앞에 . 추가

* fix: 권한 추가 삭제

* fix: cloudfront path 더해서 이미지 패스 지정

* refactor: prod yml cloudfrontPath 변수 수정

* refactor: 문자열 자르기 에러 수정
  • Loading branch information
wugawuga authored Sep 12, 2023
1 parent d6f0df7 commit d62a0b4
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions backend/src/main/java/com/funeat/common/s3/S3Uploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public String upload(final MultipartFile image) {
final String key = folder + randomImageName;
amazonS3.putObject(getPutObjectRequest(image, key, metadata));

return getCloudfrontImagePath(key);
return getCloudfrontImagePath(randomImageName);
} catch (IOException e) {
throw new S3UploadFailException(UNKNOWN_SERVER_ERROR_CODE);
}
Expand All @@ -61,8 +61,7 @@ private void validateExtension(final MultipartFile image) {
}

private String getRandomImageName(final MultipartFile image) {
final String randomImageName = UUID.randomUUID() + image.getOriginalFilename();
return randomImageName.substring(0, randomImageName.lastIndexOf("."));
return UUID.randomUUID() + image.getOriginalFilename();
}

private ObjectMetadata getMetadata(final MultipartFile image) {
Expand All @@ -77,8 +76,7 @@ private PutObjectRequest getPutObjectRequest(final MultipartFile image, final St
return new PutObjectRequest(bucket, key, image.getInputStream(), metadata);
}

private String getCloudfrontImagePath(final String key) {
final String s3Url = amazonS3.getUrl(bucket, key).toString();
return cloudfrontPath + s3Url.substring(s3Url.lastIndexOf("/"));
private String getCloudfrontImagePath(final String imageName) {
return cloudfrontPath + imageName;
}
}

0 comments on commit d62a0b4

Please sign in to comment.