Skip to content

Commit

Permalink
hotfix : s3 파일 올바른 경로로 저장되도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
huncozyboy committed Nov 11, 2024
1 parent 72ce773 commit 7d20188
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public class S3ImageService {
@Value("${cloud.aws.s3.bucket}")
private String bucketName;

@Value("${cloud.aws.region.static}")
private String region;

// 단일 이미지 업로드 메서드
public String uploadImage(MultipartFile image, String dirName) {
validateImageFileExtension(image.getOriginalFilename());
Expand Down Expand Up @@ -88,7 +91,8 @@ private File convertToFile(MultipartFile multipartFile) {
// S3에 업로드 및 URL 반환
private String uploadToS3(File uploadFile, String fileName) {
amazonS3.putObject(new PutObjectRequest(bucketName, fileName, uploadFile));
return amazonS3.getUrl(bucketName, fileName).toString();
log.info("File uploaded to S3: {}", fileName);
return String.format("https://%s.s3.%s.amazonaws.com/%s", bucketName, region, fileName);
}

// 로컬 파일 삭제
Expand All @@ -100,4 +104,7 @@ private void deleteLocalFile(File file) {
}
}

private String generateFileUrl(String fileName) {
return String.format("https://%s.s3.%s.amazonaws.com/%s", bucketName, region, fileName);
}
}

0 comments on commit 7d20188

Please sign in to comment.