|
|
|
|
@ -1,5 +1,7 @@
|
|
|
|
|
package kr.re.etri.autoflow.controllers;
|
|
|
|
|
|
|
|
|
|
import io.minio.GetObjectArgs;
|
|
|
|
|
import io.minio.MinioClient;
|
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
@ -21,6 +23,8 @@ import org.springframework.web.client.RestTemplate;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
@ -32,6 +36,8 @@ public class MinioAttachmentController {
|
|
|
|
|
|
|
|
|
|
private final MinioAttachmentService minioAttachmentService;
|
|
|
|
|
|
|
|
|
|
private final MinioClient minioClient;
|
|
|
|
|
|
|
|
|
|
@Value("${kubeflow.url}")
|
|
|
|
|
private String kubeflowBaseUrl;
|
|
|
|
|
|
|
|
|
|
@ -77,6 +83,48 @@ public class MinioAttachmentController {
|
|
|
|
|
return ResponseEntity.notFound().build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "파일 다운로드", description = "MinIO에서 파일을 다운로드합니다.")
|
|
|
|
|
@GetMapping("/download")
|
|
|
|
|
public ResponseEntity<byte[]> downloadFile(@RequestParam String objectName) {
|
|
|
|
|
try (InputStream is = minioClient.getObject(
|
|
|
|
|
GetObjectArgs.builder().bucket("mlpipeline").object(objectName).build()
|
|
|
|
|
)) {
|
|
|
|
|
byte[] bytes = is.readAllBytes();
|
|
|
|
|
|
|
|
|
|
// 파일명을 UTF-8로 URL 인코딩
|
|
|
|
|
String encodedFileName = URLEncoder.encode(objectName, StandardCharsets.UTF_8)
|
|
|
|
|
.replaceAll("\\+", "%20"); // 공백 처리
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok()
|
|
|
|
|
.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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "MinIO YAML 파일 읽기", description = "MinIO에서 YAML 파일을 다운로드하여 텍스트로 반환합니다.")
|
|
|
|
|
@GetMapping(value = "/readYamlText", produces = MediaType.TEXT_PLAIN_VALUE)
|
|
|
|
|
public ResponseEntity<String> 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);
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok(content);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("MinIO 파일 읽기 실패: " + objectName, e);
|
|
|
|
|
return ResponseEntity.internalServerError()
|
|
|
|
|
.body("Error reading file: " + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "파일 업로드", description = "MultipartFile을 MinIO 버킷에 업로드하고 DB에 기록합니다.")
|
|
|
|
|
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
|
|
|
|
public ResponseEntity<Map<String, Object>> uploadFile(
|
|
|
|
|
|