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