From fc570b38d839c3bc532629482d0aeeb7d1326f1f Mon Sep 17 00:00:00 2001 From: J-I-H-O Date: Wed, 21 Aug 2024 14:07:36 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EA=B8=B0=EB=B3=B8=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80=EC=97=90=EC=84=9C=20=EC=83=88=EB=A1=9C=EC=9A=B4=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=EB=A1=9C=20updaet=ED=95=98=EB=8A=94?= =?UTF-8?q?=20=EA=B2=BD=EC=9A=B0=20=EC=98=88=EC=99=B8=EA=B0=80=20=EB=B0=9C?= =?UTF-8?q?=EC=83=9D=ED=95=98=EB=8A=94=20=ED=98=84=EC=83=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../happy/friendogly/infra/S3StorageManager.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/backend/src/main/java/com/happy/friendogly/infra/S3StorageManager.java b/backend/src/main/java/com/happy/friendogly/infra/S3StorageManager.java index 2dc872ad0..29bd00988 100644 --- a/backend/src/main/java/com/happy/friendogly/infra/S3StorageManager.java +++ b/backend/src/main/java/com/happy/friendogly/infra/S3StorageManager.java @@ -9,6 +9,7 @@ import java.io.File; import java.io.IOException; import java.util.UUID; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; @@ -21,6 +22,7 @@ import software.amazon.awssdk.services.s3.model.DeleteObjectRequest; import software.amazon.awssdk.services.s3.model.PutObjectRequest; +@Slf4j @Component @Profile("!local") public class S3StorageManager implements FileStorageManager { @@ -59,7 +61,6 @@ public String uploadFile(MultipartFile file) { ErrorCode.FILE_SIZE_EXCEED, BAD_REQUEST ); -// throw new FriendoglyException(String.format("%dMB 미만의 사진만 업로드 가능합니다.", FILE_SIZE_LIMIT)); } // TODO: 실제 파일명에서 확장자 가져오기 @@ -93,23 +94,18 @@ private File convertMultiPartFileToFile(MultipartFile multipartFile) { @Override public void removeFile(String oldImageUrl) { - if (StringUtils.isBlank(oldImageUrl)) { - throw new FriendoglyException("삭제할 이미지의 URL을 입력해 주세요."); - } - - if (!oldImageUrl.startsWith(S3_ENDPOINT)) { - throw new FriendoglyException(String.format("(%s)은 삭제할 수 없는 이미지 URL입니다.", oldImageUrl)); + if (StringUtils.isBlank(oldImageUrl) || !oldImageUrl.startsWith(S3_ENDPOINT)) { + return; } String fileName = oldImageUrl.substring(oldImageUrl.lastIndexOf("/") + 1); - try { s3Client.deleteObject(DeleteObjectRequest.builder() .bucket(BUCKET_NAME) .key(KEY_PREFIX + fileName) .build()); - } catch (SdkException e) { - throw new FriendoglyException("알 수 없는 이유로 이미지 파일 삭제에 실패했습니다.", INTERNAL_SERVER_ERROR); + } catch (SdkException exception) { + log.error(exception.getMessage(), exception); } }