From e89f69bcced120c2a576031a9771a9170b3ab924 Mon Sep 17 00:00:00 2001 From: sunninz Date: Sun, 28 Sep 2025 14:27:24 +0900 Subject: [PATCH] =?UTF-8?q?:sparkles:=20(#324)=20s3=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=EC=8B=9C=20=EC=97=90=EB=9F=AC=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/example/backend/global/S3/exception/S3ErrorCode.java | 4 +++- .../org/example/backend/global/S3/service/S3Service.java | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/org/example/backend/global/S3/exception/S3ErrorCode.java b/backend/src/main/java/org/example/backend/global/S3/exception/S3ErrorCode.java index c3192c58..9fba3269 100644 --- a/backend/src/main/java/org/example/backend/global/S3/exception/S3ErrorCode.java +++ b/backend/src/main/java/org/example/backend/global/S3/exception/S3ErrorCode.java @@ -9,7 +9,9 @@ @Getter @AllArgsConstructor public enum S3ErrorCode implements BaseErrorCode { - UPLOAD_FAIL(HttpStatus.BAD_REQUEST, "S3_404", "업로드 실패하였습니다."); + UPLOAD_FAIL(HttpStatus.BAD_REQUEST, "S3_404", "업로드 실패하였습니다."), + _S3_NOT_FOUND(HttpStatus.NOT_FOUND,"S3400","파일이 존재하지 않습니다") + ; diff --git a/backend/src/main/java/org/example/backend/global/S3/service/S3Service.java b/backend/src/main/java/org/example/backend/global/S3/service/S3Service.java index 474a432a..dbfec491 100644 --- a/backend/src/main/java/org/example/backend/global/S3/service/S3Service.java +++ b/backend/src/main/java/org/example/backend/global/S3/service/S3Service.java @@ -5,6 +5,8 @@ import com.amazonaws.services.s3.model.*; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.example.backend.global.S3.exception.S3ErrorCode; +import org.example.backend.global.S3.exception.S3Exception; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; @@ -53,6 +55,9 @@ public void deleteFile(String key) { * Presigned URL 발급 (다운로드용) */ public String getPresignedUrl(String key) { + if(!amazonS3Client.doesObjectExist(bucket, key)) { + throw new S3Exception(S3ErrorCode._S3_NOT_FOUND); + } Date expiration = new Date(System.currentTimeMillis() + 1000 * 60 * 60); // 1시간 GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, key)