diff --git a/src/main/java/com/moing/backend/domain/mypage/application/service/ProfileUseCase.java b/src/main/java/com/moing/backend/domain/mypage/application/service/ProfileUseCase.java index fc7c88ca..979f060a 100644 --- a/src/main/java/com/moing/backend/domain/mypage/application/service/ProfileUseCase.java +++ b/src/main/java/com/moing/backend/domain/mypage/application/service/ProfileUseCase.java @@ -9,6 +9,7 @@ import org.springframework.stereotype.Service; import javax.transaction.Transactional; +import java.util.concurrent.CompletableFuture; @Service @RequiredArgsConstructor @@ -41,8 +42,10 @@ private String getUpdatedValue(String newValue, String currentValue) { } private void deletePreviousImage(UpdateProfileRequest updateProfileRequest, Member member) { - if (updateProfileRequest.getProfileImage() != null) { - s3Service.deleteImage(member.getProfileImage()); + if (updateProfileRequest.getProfileImage() != null && member.getProfileImage() != null) { + CompletableFuture.runAsync(() -> { + s3Service.deleteImage(member.getProfileImage()); + }); } } diff --git a/src/main/java/com/moing/backend/global/config/s3/S3Service.java b/src/main/java/com/moing/backend/global/config/s3/S3Service.java index 253a0de9..5f39dfdc 100644 --- a/src/main/java/com/moing/backend/global/config/s3/S3Service.java +++ b/src/main/java/com/moing/backend/global/config/s3/S3Service.java @@ -42,10 +42,12 @@ public void deleteImage(String fileUrl) { String splitStr = ".com/"; String fileName = fileUrl.substring(fileUrl.lastIndexOf(splitStr) + splitStr.length()); - amazonS3.deleteObject(new DeleteObjectRequest(bucket, fileName)); + if (amazonS3.doesObjectExist(bucket, fileName)) { + amazonS3.deleteObject(new DeleteObjectRequest(bucket, fileName)); + } } - private String createFileName(String fileExtension) { + private String createFileName(String fileExtension) { return UUID.randomUUID() + "." + fileExtension; }