TIF 파일 유효성 검증 및 중복 파일 삭제 기능 적용
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user