Skip to content

Commit

Permalink
refactor: PresignedUrlPut 파라미터 수정 #33
Browse files Browse the repository at this point in the history
  • Loading branch information
jjt4515 committed Oct 12, 2024
1 parent ab050b5 commit b8eea9a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public String createPresignedPutUrl(String bucketName, String keyPrefix, Map<Str
String date = now.format(DATE_FORMATTER);
String encodedTime = encryptionUtil.encodeTime(now).substring(0, 10);

// jpg 말고 다른 형식 파일 들어오는 경우에 대해서도 따로 처리 필요
String keyName = String.format("%s/%s/%s.jpg", keyPrefix, date, encodedTime);

PutObjectRequest objectRequest = PutObjectRequest.builder()
Expand All @@ -63,7 +64,6 @@ public String createPresignedPutUrl(String bucketName, String keyPrefix, Map<Str
.putObjectRequest(objectRequest)
.build();


PresignedPutObjectRequest presignedRequest = s3Presigner.presignPutObject(presignRequest);
String myURL = presignedRequest.url().toString();
log.info("Presigned URL to upload a file to: [{}]", myURL);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package poomasi.global.config.s3.dto.request;

import java.util.Map;

public record PresignedUrlPutRequest(String keyPrefix, Map<String, String> metadata) {
}

0 comments on commit b8eea9a

Please sign in to comment.