diff --git a/src/main/java/poomasi/global/config/s3/TestController.java b/src/main/java/poomasi/global/config/s3/S3PresignedUrlController.java similarity index 54% rename from src/main/java/poomasi/global/config/s3/TestController.java rename to src/main/java/poomasi/global/config/s3/S3PresignedUrlController.java index 97e2eb9..ede4e03 100644 --- a/src/main/java/poomasi/global/config/s3/TestController.java +++ b/src/main/java/poomasi/global/config/s3/S3PresignedUrlController.java @@ -2,24 +2,28 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import poomasi.global.config.aws.AwsProperties; +import poomasi.global.config.s3.dto.request.PresignedUrlPutRequest; @RestController @RequiredArgsConstructor -public class TestController { +@RequestMapping("/api/s3") +public class S3PresignedUrlController { private final S3PresignedUrlService s3PresignedUrlService; + private final AwsProperties awsProperties; - @GetMapping("/presigned-url-put") - public ResponseEntity presignedUrlPut() { - String presignedPutUrl = s3PresignedUrlService.createPresignedPutUrl("poomasi", "test", null); - return ResponseEntity.ok(presignedPutUrl); - } + String bucket = awsProperties.getS3().getBucket(); @GetMapping("/presigned-url-get") public ResponseEntity presignedUrlGet(@RequestParam String keyname) { - String presignedGetUrl = s3PresignedUrlService.createPresignedGetUrl("poomasi", keyname); + String presignedGetUrl = s3PresignedUrlService.createPresignedGetUrl(bucket, keyname); return ResponseEntity.ok(presignedGetUrl); } + + @GetMapping("/presigned-url-put") + public ResponseEntity presignedUrlPut(@RequestBody PresignedUrlPutRequest request) { + String presignedPutUrl = s3PresignedUrlService.createPresignedPutUrl(bucket, request.keyPrefix(), request.metadata()); + return ResponseEntity.ok(presignedPutUrl); + } } diff --git a/src/main/java/poomasi/global/config/s3/S3PresignedUrlService.java b/src/main/java/poomasi/global/config/s3/S3PresignedUrlService.java index 17391d0..d92b5c8 100644 --- a/src/main/java/poomasi/global/config/s3/S3PresignedUrlService.java +++ b/src/main/java/poomasi/global/config/s3/S3PresignedUrlService.java @@ -50,6 +50,7 @@ public String createPresignedPutUrl(String bucketName, String keyPrefix, Map metadata) { +}