Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/cd-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ jobs:
-e SPRING_PROFILES_ACTIVE=prod \
-e FRONT_ORIGIN=${{ secrets.FRONT_ORIGIN }} \
-e S3_BUCKET_NAME=${{ secrets.S3_BUCKET_NAME }} \
-e S3_BUCKET_URL=${{ secrets.S3_BUCKET_URL }} \
-e S3_ACCESS_KEY=${{ secrets.S3_ACCESS_KEY }} \
-e S3_SECRET_KEY=${{ secrets.S3_SECRET_KEY }} \
-e S3_REGION=${{ secrets.S3_REGION }} \
-e CLOUD_FRONT_URL=${{ secrets.CLOUD_FRONT_URL }} \
-e DATA_INIT_MASTER_EMAIL=${{ secrets.DATA_INIT_MASTER_EMAIL }} \
-e DATA_INIT_MASTER_PASSWORD=${{ secrets.DATA_INIT_MASTER_PASSWORD }} \
-e PROD_DB_URL=${{ secrets.PROD_DB_URL }} \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class DataInitializer implements CommandLineRunner {
@Value("${data-initialization.user.master.password}")
private String masterPassword;

@Value("${cloud.aws.s3.bucket-url}")
private String bucketUrl;
@Value("${cloud.aws.cloud-front-url}")
private String cloudFrontUrl;

@Override
@Transactional
Expand Down Expand Up @@ -68,7 +68,7 @@ public void run(String... args) throws Exception {
private Icon createDefaultIcon(String name) {
return Icon.builder()
.name(name)
.imageUrl(bucketUrl + "/" + name + ".svg")
.imageUrl(cloudFrontUrl + "/" + name + ".svg")
.owner(null)
.isDefault(true)
.status(Status.ACTIVE)
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/com/linku/backend/global/util/S3Uploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.springframework.stereotype.Component;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.GetUrlRequest;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;

import java.util.UUID;
Expand All @@ -19,6 +18,9 @@ public class S3Uploader {
@Value("${cloud.aws.s3.bucket-name}")
private String bucketName;

@Value("${cloud.aws.cloud-front-url}")
private String cloudFrontUrl;

private final S3Client s3Client;

public String uploadFile(byte[] data, String originalFilename, String contentType) {
Expand All @@ -36,12 +38,7 @@ public String uploadFile(byte[] data, String originalFilename, String contentTyp

s3Client.putObject(putObjectRequest, RequestBody.fromBytes(data));

GetUrlRequest getUrlRequest = GetUrlRequest.builder()
.bucket(bucketName)
.key(fileName)
.build();

return s3Client.utilities().getUrl(getUrlRequest).toString();
return cloudFrontUrl + "/" + fileName;
}

public String buildFileName(String originalFileName) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ cloud:
aws:
s3:
bucket-name: ${S3_BUCKET_NAME}
bucket-url: ${S3_BUCKET_URL}
credentials:
access-key: ${S3_ACCESS_KEY}
secret-key: ${S3_SECRET_KEY}
region:
static: ${S3_REGION}
cloud-front-url: ${CLOUD_FRONT_URL}

data-initialization:
user:
Expand Down
Loading