Skip to content

Commit

Permalink
refactor: S3 이미지 삭제 기능 개선
Browse files Browse the repository at this point in the history
- S3 객체 키 추출 로직 수정으로 정확한 이미지 삭제 구현
- 파일 타입 식별을 위한 확장자 추가

CHZZ-116
  • Loading branch information
viaunixue committed Oct 1, 2024
1 parent e20d771 commit e477f97
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import com.amazonaws.AmazonServiceException;
import com.amazonaws.services.s3.AmazonS3;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -85,9 +87,13 @@ public void deleteUploadImages(List<String> fullImageUrls) {
*/
private void deleteImage(String cdnPath) {
try {
String key = cdnPath.substring(1);
URL url = new URL(cdnPath);
String path = url.getPath();
String key = path.substring(1);

log.info("S3에서 객체 삭제 시도, Key : {}", key);
amazonS3Client.deleteObject(bucket, key);
} catch (AmazonServiceException e) {
} catch (AmazonServiceException | MalformedURLException e) {
throw new ImageException(IMAGE_DELETE_FAILED);
}
}
Expand All @@ -103,7 +109,7 @@ private String createUniqueFileName(String originalFileName) {
throw new ImageException(INVALID_IMAGE_EXTENSION);
}

return uuid;
return uuid + "." + extension;
}

/**
Expand Down

0 comments on commit e477f97

Please sign in to comment.