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)