Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Refactor/313 CloudFront 사용하도록 변경 #314

Merged
merged 1 commit into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading