From 88cdcaa1173a8514380817e749c51600716f2a28 Mon Sep 17 00:00:00 2001 From: Gyoungmin Kim Date: Sun, 27 Oct 2024 01:13:57 +0900 Subject: [PATCH] hotfix: fix object storage filePath format error * feat: implement extractFileType --- .../kr/mafoo/photo/service/ObjectStorageService.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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; }