Skip to content

Commit 449c631

Browse files
committed
fix: S3 업로드 SDK 예외 미처리 및 base-url 미설정 시 잘못된 URL 반환 수정
- S3ProfileImageStorage, S3VerificationFileStorage: putObject 호출 시 SdkClientException 등 SDK 런타임 예외가 IOException catch에 잡히지 않아 500 핸들러 없이 전파되던 문제 수정 (IOException과 SDK 예외 catch 분리) - S3ProfileImageStorage: storage-type=s3 전환 시 PROFILE_IMAGE_S3_BASE_URL, PROFILE_IMAGE_S3_KEY_PREFIX 미설정이면 빈 URL을 반환하던 문제 수정 (생성자에서 필수 값 검증, IllegalStateException으로 조기 실패)
1 parent c08cd56 commit 449c631

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

src/main/java/com/bootsignal/domain/user/storage/S3ProfileImageStorage.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ public S3ProfileImageStorage(
3030
AwsProperties awsProperties,
3131
ProfileImageProperties profileImageProperties
3232
) {
33+
if (profileImageProperties.s3() == null
34+
|| !StringUtils.hasText(profileImageProperties.s3().baseUrl())
35+
|| !StringUtils.hasText(profileImageProperties.s3().keyPrefix())) {
36+
throw new IllegalStateException(
37+
"storage-type=s3 설정 시 PROFILE_IMAGE_S3_BASE_URL, PROFILE_IMAGE_S3_KEY_PREFIX 환경 변수가 필요합니다."
38+
);
39+
}
3340
this.s3Client = s3Client;
3441
this.awsProperties = awsProperties;
3542
this.profileImageProperties = profileImageProperties;
@@ -42,6 +49,13 @@ public String store(MultipartFile file, Long userId) {
4249
String extension = resolveExtension(file);
4350
String key = profileImageProperties.s3().keyPrefix() + "/" + userId + "_" + UUID.randomUUID() + extension;
4451

52+
byte[] bytes;
53+
try {
54+
bytes = file.getBytes();
55+
} catch (IOException exception) {
56+
throw new BootSignalException(ErrorCode.INTERNAL_SERVER_ERROR, "프로필 이미지 저장에 실패했습니다.");
57+
}
58+
4559
try {
4660
s3Client.putObject(
4761
PutObjectRequest.builder()
@@ -50,9 +64,9 @@ public String store(MultipartFile file, Long userId) {
5064
.contentType(file.getContentType())
5165
.contentLength(file.getSize())
5266
.build(),
53-
RequestBody.fromBytes(file.getBytes())
67+
RequestBody.fromBytes(bytes)
5468
);
55-
} catch (IOException exception) {
69+
} catch (Exception exception) {
5670
throw new BootSignalException(ErrorCode.INTERNAL_SERVER_ERROR, "프로필 이미지 저장에 실패했습니다.");
5771
}
5872

src/main/java/com/bootsignal/domain/verification/storage/S3VerificationFileStorage.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ public String upload(MultipartFile file, String keyPrefix) {
3131
String extension = resolveExtension(originalFilename);
3232
String key = keyPrefix + "/" + UUID.randomUUID() + extension;
3333

34+
byte[] bytes;
35+
try {
36+
bytes = file.getBytes();
37+
} catch (IOException exception) {
38+
throw new BootSignalException(ErrorCode.INTERNAL_SERVER_ERROR, "인증 자료 업로드에 실패했습니다.");
39+
}
40+
3441
try {
3542
s3Client.putObject(
3643
PutObjectRequest.builder()
@@ -39,9 +46,9 @@ public String upload(MultipartFile file, String keyPrefix) {
3946
.contentType(resolveContentType(file))
4047
.contentLength(file.getSize())
4148
.build(),
42-
RequestBody.fromBytes(file.getBytes())
49+
RequestBody.fromBytes(bytes)
4350
);
44-
} catch (IOException exception) {
51+
} catch (Exception exception) {
4552
throw new BootSignalException(ErrorCode.INTERNAL_SERVER_ERROR, "인증 자료 업로드에 실패했습니다.");
4653
}
4754

0 commit comments

Comments
 (0)