From ac3bdcb431e6148eff3fe4b64f2d6b38b94f772e Mon Sep 17 00:00:00 2001 From: DanielLee <198891672+sanghyeonhd@users.noreply.github.com> Date: Fri, 12 Dec 2025 15:03:37 +0900 Subject: [PATCH] =?UTF-8?q?=20TIF=20=ED=8C=8C=EC=9D=BC=20=EC=9C=A0?= =?UTF-8?q?=ED=9A=A8=EC=84=B1=20=EA=B2=80=EC=A6=9D=20=EB=B0=8F=20=EC=A4=91?= =?UTF-8?q?=EB=B3=B5=20=ED=8C=8C=EC=9D=BC=20=EC=82=AD=EC=A0=9C=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MapSheetMngFileCheckerApiController.java | 18 +++++++ .../MapSheetMngFileCheckerService.java | 48 +++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/src/main/java/com/kamco/cd/kamcoback/mapsheet/MapSheetMngFileCheckerApiController.java b/src/main/java/com/kamco/cd/kamcoback/mapsheet/MapSheetMngFileCheckerApiController.java index 260e7775..e702e106 100644 --- a/src/main/java/com/kamco/cd/kamcoback/mapsheet/MapSheetMngFileCheckerApiController.java +++ b/src/main/java/com/kamco/cd/kamcoback/mapsheet/MapSheetMngFileCheckerApiController.java @@ -15,10 +15,14 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; @Tag(name = "영상 관리", description = "영상 관리 API") @RestController @@ -67,6 +71,20 @@ public class MapSheetMngFileCheckerApiController { return ApiResponseDto.createOK(mapSheetMngFileCheckerService.getFilesAll(srchDto)); } + @Operation(summary = "파일 업로드", description = "파일 업로드 및 TIF 검증") + @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + public ApiResponseDto uploadFile( + @RequestPart("file") MultipartFile file, + @RequestParam("targetPath") String targetPath) { + return ApiResponseDto.createOK(mapSheetMngFileCheckerService.uploadFile(file, targetPath)); + } + + @Operation(summary = "파일 삭제", description = "중복 파일 등 파일 삭제") + @PostMapping("/delete") + public ApiResponseDto deleteFile(@RequestBody SrchFoldersDto dto) { + return ApiResponseDto.createOK(mapSheetMngFileCheckerService.deleteFile(dto.getDirPath())); + } + /* @Operation(summary = "지정폴더(하위폴더포함) 파일목록 조회", description = "지정폴더(하위폴더포함) 파일목록 조회") @ApiResponses( diff --git a/src/main/java/com/kamco/cd/kamcoback/mapsheet/service/MapSheetMngFileCheckerService.java b/src/main/java/com/kamco/cd/kamcoback/mapsheet/service/MapSheetMngFileCheckerService.java index 575a513a..fc38a92f 100644 --- a/src/main/java/com/kamco/cd/kamcoback/mapsheet/service/MapSheetMngFileCheckerService.java +++ b/src/main/java/com/kamco/cd/kamcoback/mapsheet/service/MapSheetMngFileCheckerService.java @@ -2,6 +2,7 @@ package com.kamco.cd.kamcoback.mapsheet.service; import static java.lang.String.CASE_INSENSITIVE_ORDER; +import com.kamco.cd.kamcoback.common.utils.FIleChecker; import com.kamco.cd.kamcoback.common.utils.NameValidator; import com.kamco.cd.kamcoback.config.FileConfig; import com.kamco.cd.kamcoback.mapsheet.dto.FileDto; @@ -32,6 +33,7 @@ import lombok.RequiredArgsConstructor; import org.apache.commons.io.FilenameUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; @Service @RequiredArgsConstructor @@ -304,4 +306,50 @@ public class MapSheetMngFileCheckerService { public ImageryDto.SyncReturn syncProcess(ImageryDto.searchReq searchReq) { return mapSheetMngFileCheckerCoreService.syncProcess(searchReq); } + + @Transactional + public String uploadFile(MultipartFile file, String targetPath) { + try { + Path path = Paths.get(targetPath); + // If targetPath is a directory, append the original filename + if (Files.isDirectory(path)) { + path = path.resolve(file.getOriginalFilename()); + } else if (Files.notExists(path) && Files.isDirectory(path.getParent())) { + // If path doesn't exist but parent is a directory, assume it's the full path + // (No change needed) + } + + // Ensure parent directory exists + if (path.getParent() != null) { + Files.createDirectories(path.getParent()); + } + + // Save file + file.transferTo(path.toFile()); + + // Check TIF using Gdal functionality + String ext = FilenameUtils.getExtension(path.getFileName().toString()); + if ("tif".equalsIgnoreCase(ext) || "tiff".equalsIgnoreCase(ext)) { + boolean isValid = FIleChecker.cmmndGdalInfo(path.toString()); + if (!isValid) { + Files.delete(path); // Delete invalid file + throw new RuntimeException("유효하지 않은 TIF 파일입니다 (Gdal 검증 실패)."); + } + } + + return "업로드 성공"; + } catch (IOException e) { + throw new RuntimeException("파일 업로드 실패: " + e.getMessage()); + } + } + + @Transactional + public Boolean deleteFile(String filePath) { + try { + Path path = Paths.get(filePath); + return Files.deleteIfExists(path); + } catch (IOException e) { + throw new RuntimeException("파일 삭제 실패: " + e.getMessage()); + } + } }