From 1452b1265a55caad93d5d86b0af22ea348159862 Mon Sep 17 00:00:00 2001 From: bjkim Date: Mon, 20 Oct 2025 16:04:02 +0900 Subject: [PATCH] =?UTF-8?q?[ADD]=20MinIO=20=ED=8C=8C=EC=9D=BC=20=EB=8B=A4?= =?UTF-8?q?=EC=9A=B4=EB=A1=9C=EB=93=9C=20=EB=B0=8F=20YAML=20=EC=9D=BD?= =?UTF-8?q?=EA=B8=B0=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80,=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20Service=20=EB=B0=8F=20Controller=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MinioAttachmentController.java | 24 +++++------------- .../service/MinioAttachmentService.java | 25 ++++++++++++++++++- 2 files changed, 30 insertions(+), 19 deletions(-) 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, // 추가