From b88d23873c0e12fa00ae604ae664b0c55a240cb9 Mon Sep 17 00:00:00 2001 From: Hanvp Date: Sat, 17 Feb 2024 18:02:44 +0900 Subject: [PATCH] =?UTF-8?q?:recycle:=20Refactor/313=20CloudFront=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/zipdabang/server/aws/s3/AmazonS3Manager.java | 9 ++++++++- src/main/resources/application.yml | 7 ++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/zipdabang/server/aws/s3/AmazonS3Manager.java b/src/main/java/zipdabang/server/aws/s3/AmazonS3Manager.java index b5e1cb5..ba43b25 100644 --- a/src/main/java/zipdabang/server/aws/s3/AmazonS3Manager.java +++ b/src/main/java/zipdabang/server/aws/s3/AmazonS3Manager.java @@ -5,6 +5,7 @@ import com.amazonaws.services.s3.model.PutObjectRequest; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; import zipdabang.server.config.AmazonConfig; @@ -24,13 +25,19 @@ public class AmazonS3Manager { private final AmazonConfig amazonConfig; private final UuidRepository uuidRepository; + @Value("${cloud.aws.cloudfront.uri}") + private String cloudfrontUri; + + public String uploadFile(String KeyName, MultipartFile file) throws IOException { System.out.println(KeyName); ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(file.getSize()); amazonS3.putObject(new PutObjectRequest(amazonConfig.getBucket(), KeyName,file.getInputStream(), metadata)); - return amazonS3.getUrl(amazonConfig.getBucket(), KeyName).toString(); + return cloudfrontUri+amazonS3.getUrl(amazonConfig.getBucket(), KeyName).getPath(); + + //return amazonS3.getUrl(amazonConfig.getBucket(), KeyName).toString(); } public String getPattern(){ diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 8351375..7125faf 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -85,7 +85,8 @@ cloud: credentials: accessKey: ${AWS_ACCESS_KEY_ID} secretKey: ${AWS_SECRET_ACCESS_KEY} - + cloudfront: + uri: ${AWS_CLOUDFRONT} jwt: header: Authorization @@ -182,6 +183,8 @@ cloud: credentials: accessKey: ${AWS_ACCESS_KEY_ID} secretKey: ${AWS_SECRET_ACCESS_KEY} + cloudfront: + uri: ${AWS_CLOUDFRONT} jwt: header: Authorization @@ -276,6 +279,8 @@ cloud: credentials: accessKey: ${AWS_ACCESS_KEY_ID} secretKey: ${AWS_SECRET_ACCESS_KEY} + cloudfront: + uri: ${CLOUDFRONT} jwt: header: Authorization