Skip to content

Commit

Permalink
♻️ Refactor/313 CloudFront 사용하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanvp committed Feb 17, 2024
1 parent 83b6bcc commit b88d238
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/main/java/zipdabang/server/aws/s3/AmazonS3Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(){
Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ cloud:
credentials:
accessKey: ${AWS_ACCESS_KEY_ID}
secretKey: ${AWS_SECRET_ACCESS_KEY}

cloudfront:
uri: ${AWS_CLOUDFRONT}

jwt:
header: Authorization
Expand Down Expand Up @@ -182,6 +183,8 @@ cloud:
credentials:
accessKey: ${AWS_ACCESS_KEY_ID}
secretKey: ${AWS_SECRET_ACCESS_KEY}
cloudfront:
uri: ${AWS_CLOUDFRONT}

jwt:
header: Authorization
Expand Down Expand Up @@ -276,6 +279,8 @@ cloud:
credentials:
accessKey: ${AWS_ACCESS_KEY_ID}
secretKey: ${AWS_SECRET_ACCESS_KEY}
cloudfront:
uri: ${CLOUDFRONT}

jwt:
header: Authorization
Expand Down

0 comments on commit b88d238

Please sign in to comment.