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] hotfix: image 문자열 자르기 에러 수정 #604

Merged
merged 7 commits into from
Sep 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}