Skip to content

Commit

Permalink
[merge] 유저 프로필 이미지 기본 url 오류 해결 - #289
Browse files Browse the repository at this point in the history
[FIX] 유저 프로필 이미지 기본 url 오류 해결
  • Loading branch information
gardening-y authored Sep 28, 2024
2 parents 8e67bed + 3f4125a commit f9c2a47
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions dateroad-external/src/main/java/org/dateroad/s3/S3Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import org.dateroad.code.FailureCode;
import org.dateroad.exception.BadRequestException;
import org.dateroad.exception.InvalidValueException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import software.amazon.awssdk.core.sync.RequestBody;
Expand All @@ -27,12 +24,14 @@
public class S3Service {
private final String bucketName;
private final AWSConfig awsConfig;
private final String basePath;
private static final List<String> IMAGE_EXTENSIONS = Arrays.asList("image/jpeg", "image/png", "image/jpg", "image/webp", "image/heic", "image/heif");
private static final Long MAX_FILE_SIZE = 7 * 1024 * 1024L;

public S3Service(@Value("${aws-property.s3-bucket-name}") final String bucketName, AWSConfig awsConfig) {
public S3Service(@Value("${aws-property.s3-bucket-name}") final String bucketName, AWSConfig awsConfig, @Value("${cloudfront.domain}") String basePath) {
this.bucketName = bucketName;
this.awsConfig = awsConfig;
this.basePath = basePath;
}

public String uploadImage(String directoryPath, MultipartFile image) throws IOException {
Expand Down Expand Up @@ -98,9 +97,8 @@ private void validateFileSize(MultipartFile image) {
}
}

private static String extractImageKeyFromImageUrl(String url) {
String basePath = "https://d2rjs92glrj91n.cloudfront.net";
if (url.startsWith(basePath)) {
private String extractImageKeyFromImageUrl(String url) {
if (url.startsWith(this.basePath)) {
return url.substring(basePath.length());
} else {
throw new BadRequestException(FailureCode.WRONG_IMAGE_URL);
Expand Down

0 comments on commit f9c2a47

Please sign in to comment.