diff --git a/src/main/java/kr/re/etri/autoflow/controllers/MinioAttachmentController.java b/src/main/java/kr/re/etri/autoflow/controllers/MinioAttachmentController.java index 08ee709..6921b78 100644 --- a/src/main/java/kr/re/etri/autoflow/controllers/MinioAttachmentController.java +++ b/src/main/java/kr/re/etri/autoflow/controllers/MinioAttachmentController.java @@ -45,9 +45,6 @@ public class MinioAttachmentController { private final MinioClient minioClient; - @Value("${kubeflow.url}") - private String kubeflowBaseUrl; - @Operation(summary = "첨부파일 전체 조회") @GetMapping public ResponseEntity> getAll() { @@ -93,12 +90,9 @@ public class MinioAttachmentController { @Operation(summary = "파일 다운로드", description = "MinIO에서 파일을 다운로드합니다.") @GetMapping("/download") public ResponseEntity downloadFile(@RequestParam String objectName) { - try (InputStream is = minioClient.getObject( - GetObjectArgs.builder().bucket("mlpipeline").object(objectName).build() - )) { - byte[] bytes = is.readAllBytes(); + try { + byte[] bytes = minioAttachmentService.downloadFile("mlpipeline", objectName); - // 파일명을 UTF-8로 URL 인코딩 String encodedFileName = URLEncoder.encode(objectName, StandardCharsets.UTF_8) .replaceAll("\\+", "%20"); // 공백 처리 @@ -106,6 +100,7 @@ public class MinioAttachmentController { .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename*=UTF-8''" + encodedFileName) .contentType(MediaType.APPLICATION_OCTET_STREAM) .body(bytes); + } catch (Exception e) { log.error("파일 다운로드 실패", e); return ResponseEntity.internalServerError().build(); @@ -143,18 +138,11 @@ public class MinioAttachmentController { @Operation(summary = "MinIO YAML 파일 읽기", description = "MinIO에서 YAML 파일을 다운로드하여 텍스트로 반환합니다.") @GetMapping(value = "/readYamlText", produces = MediaType.TEXT_PLAIN_VALUE) public ResponseEntity readYamlTextFromMinio(@RequestParam String objectName) { - try (InputStream is = minioClient.getObject( - GetObjectArgs.builder() - .bucket("mlpipeline") - .object(objectName) - .build() - )) { - // InputStream을 문자열로 변환 (UTF-8) - String content = new String(is.readAllBytes(), StandardCharsets.UTF_8); - + try { + String content = minioAttachmentService.readYamlText("mlpipeline", objectName); return ResponseEntity.ok(content); } catch (Exception e) { - log.error("MinIO 파일 읽기 실패: " + objectName, e); + log.error("MinIO 파일 읽기 실패: {}", objectName, e); return ResponseEntity.internalServerError() .body("Error reading file: " + e.getMessage()); } diff --git a/src/main/java/kr/re/etri/autoflow/service/MinioAttachmentService.java b/src/main/java/kr/re/etri/autoflow/service/MinioAttachmentService.java index 0110fac..a358a8f 100644 --- a/src/main/java/kr/re/etri/autoflow/service/MinioAttachmentService.java +++ b/src/main/java/kr/re/etri/autoflow/service/MinioAttachmentService.java @@ -1,5 +1,6 @@ package kr.re.etri.autoflow.service; +import io.minio.GetObjectArgs; import io.minio.MinioClient; import io.minio.PutObjectArgs; import io.minio.RemoveObjectArgs; @@ -19,6 +20,7 @@ import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; @@ -142,7 +144,6 @@ public class MinioAttachmentService { return minioAttachmentRepository.findAll(spec, pageable); } - private LocalDate parseDate(String dateStr) { if (dateStr == null || dateStr.isBlank()) return null; try { @@ -152,6 +153,28 @@ public class MinioAttachmentService { } } + public byte[] downloadFile(String bucketName, String objectName) { + try (InputStream is = minioClient.getObject( + GetObjectArgs.builder().bucket(bucketName).object(objectName).build() + )) { + return is.readAllBytes(); + } catch (Exception e) { + throw new RuntimeException("MinIO 파일 다운로드 실패: " + objectName, e); + } + } + + + // YAML 텍스트 읽기 + public String readYamlText(String bucketName, String objectName) { + try (InputStream is = minioClient.getObject( + GetObjectArgs.builder().bucket(bucketName).object(objectName).build() + )) { + return new String(is.readAllBytes(), StandardCharsets.UTF_8); + } catch (Exception e) { + throw new RuntimeException("MinIO YAML 읽기 실패: " + objectName, e); + } + } + public MinioAttachmentEntity updateFile( Long id, Long projectId, // 추가