diff --git a/photo-service/src/main/java/kr/mafoo/photo/service/ObjectStorageService.java b/photo-service/src/main/java/kr/mafoo/photo/service/ObjectStorageService.java index e786aa3..9072cb6 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/service/ObjectStorageService.java +++ b/photo-service/src/main/java/kr/mafoo/photo/service/ObjectStorageService.java @@ -39,7 +39,7 @@ public class ObjectStorageService { private long presignedUrlExpiration; public Mono uploadFile(byte[] fileByte) { - String keyName = "qr/" + UUID.randomUUID(); + String keyName = "qr/" + UUID.randomUUID() + ".jpeg"; ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentLength(fileByte.length); @@ -71,7 +71,8 @@ public Mono createPreSignedUrls(String[] fileNames, String memberId) { } private URL generatePresignedUrl(String fileName, String memberId) { - String filePath = String.format("%s/photo/%s_%s", memberId, UUID.randomUUID(), fileName); + String fileType = extractFileType(fileName); + String filePath = String.format("%s/photo/%s.%s", memberId, UUID.randomUUID(), fileType); Date expiration = new Date(System.currentTimeMillis() + presignedUrlExpiration); return amazonS3Client.generatePresignedUrl(new GeneratePresignedUrlRequest(bucketName, filePath) @@ -92,6 +93,10 @@ public Mono setObjectPublicRead(String filePath) { }); } + private String extractFileType(String fileName) { + return fileName.substring(fileName.lastIndexOf(".") + 1); + } + private String generateFileLink(String keyName) { return endpoint + "/" + bucketName + "/" + keyName; }