From cb41405a600697a2523f96a8e829d75937b09e1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=8D=EC=B0=BD=EA=B8=B0?= Date: Tue, 24 Sep 2024 16:28:19 +0900 Subject: [PATCH] =?UTF-8?q?Refactor:=20zip=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=97=85=EB=A1=9C=EB=93=9C=20=EC=8B=9C=20=ED=8F=B4=EB=8D=94=20?= =?UTF-8?q?=EC=95=88=EC=97=90=20=ED=8F=B4=EB=8D=94=EA=B0=80=20=ED=95=98?= =?UTF-8?q?=EB=82=98=20=EB=8D=94=20=EC=83=9D=EA=B8=B0=EB=8A=94=20=ED=98=84?= =?UTF-8?q?=EC=83=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/image/service/ImageService.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/worlabel/domain/image/service/ImageService.java b/backend/src/main/java/com/worlabel/domain/image/service/ImageService.java index 716aefa..098a430 100644 --- a/backend/src/main/java/com/worlabel/domain/image/service/ImageService.java +++ b/backend/src/main/java/com/worlabel/domain/image/service/ImageService.java @@ -147,7 +147,32 @@ public class ImageService { unzip(folderOrZip, tempDir.toString()); // 압축 풀린 폴더를 재귀적으로 탐색하여 하위 폴더 및 이미지 파일을 저장 - processFolderRecursively(tempDir.toFile(), parentFolder, project); + if (tempDir.toFile().exists()) { + File[] files = tempDir.toFile().listFiles(); + + if (files != null) { + for (File file : files) { + if (file.isDirectory()) { + // 하위 폴더인 경우 재귀 호출 + processFolderRecursively(file, parentFolder, project); + } else if (isImageFile(file)) { + // 이미지 파일인 경우 + String fileName = file.getName(); + String extension = fileName.substring(fileName.lastIndexOf(".") + 1); + + try (InputStream inputStream = new FileInputStream(file)) { + // InputStream으로 S3 업로드 + String imageKey = s3UploadService.uploadFromInputStream(inputStream, extension, project.getId(), file.getName()); + + Image image = Image.of(file.getName(), imageKey, extension, parentFolder); + imageRepository.save(image); + } catch (IOException e) { + throw new CustomException(ErrorCode.FAIL_TO_CREATE_FILE); + } + } + } + } + } } else { // 압축 파일이 아닌 경우 (단일 폴더 또는 파일) File tempFolder = new File(System.getProperty("java.io.tmpdir"), originalFilename); @@ -163,8 +188,8 @@ public class ImageService { if (directory.exists() && directory.isDirectory()) { Folder currentFolder = Folder.of(directory.getName(), parentFolder, project); folderRepository.save(currentFolder); - File[] files = directory.listFiles(); + if (files != null) { for (File file : files) { if (file.isDirectory()) {