|
|
|
|
@ -14,7 +14,10 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.core.io.InputStreamResource;
|
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
import org.springframework.http.*;
|
|
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
import org.springframework.util.MultiValueMap;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
@ -83,11 +86,13 @@ public class MinioAttachmentController {
|
|
|
|
|
@RequestParam(value = "title", required = false) String title,
|
|
|
|
|
@RequestParam(value = "description", required = false) String description,
|
|
|
|
|
@RequestParam(value = "version", required = false, defaultValue = "1") Integer version,
|
|
|
|
|
@RequestParam(value = "regUserId") String regUserId
|
|
|
|
|
@RequestParam(value = "regUserId") String regUserId,
|
|
|
|
|
@RequestParam(value = "projectId") Long projectId
|
|
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
try {
|
|
|
|
|
MinioAttachmentEntity saved = minioAttachmentService.uploadFile(
|
|
|
|
|
file, path, refId, refType, title, description, version, regUserId
|
|
|
|
|
file, path, refId, refType, title, description, version, regUserId, projectId
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Map<String, Object> response = new HashMap<>();
|
|
|
|
|
@ -102,51 +107,52 @@ public class MinioAttachmentController {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Operation(summary = "파일 업로드 및 Kubeflow 업로드",
|
|
|
|
|
// description = "MinIO와 DB에 저장하고 Kubeflow REST API에도 업로드합니다. Kubeflow API 경로는 요청 시 지정 가능")
|
|
|
|
|
// @PostMapping(value = "/upload-and-kubeflow", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
|
|
|
|
// public ResponseEntity<Map<String, Object>> uploadFileAndKubeflow(
|
|
|
|
|
// @Parameter(description = "업로드할 파일") @RequestPart("file") MultipartFile file,
|
|
|
|
|
// @RequestPart(value = "path", required = false) String path,
|
|
|
|
|
// @RequestParam(value = "refId", required = false) Long refId,
|
|
|
|
|
// @RequestParam(value = "refType", required = false, defaultValue = "TRAINING_SCRIPT") String refType,
|
|
|
|
|
// @RequestParam(value = "title", required = false) String title,
|
|
|
|
|
// @RequestParam(value = "description", required = false) String description,
|
|
|
|
|
// @RequestParam(value = "version", required = false, defaultValue = "1") Integer version,
|
|
|
|
|
// @RequestParam(value = "regUserId") String regUserId,
|
|
|
|
|
// @RequestParam(value = "kubeflowApi") String kubeflowApi
|
|
|
|
|
// ) {
|
|
|
|
|
// Map<String, Object> response = new HashMap<>();
|
|
|
|
|
// try {
|
|
|
|
|
// MinioAttachmentEntity saved = minioAttachmentService.uploadFile(
|
|
|
|
|
// file, path, refId, refType, title, description, version, regUserId
|
|
|
|
|
// );
|
|
|
|
|
// String minioUrl = minioAttachmentService.getFileUrl(saved.getStoragePath());
|
|
|
|
|
// response.put("attachment", saved);
|
|
|
|
|
// response.put("minioUrl", minioUrl);
|
|
|
|
|
//
|
|
|
|
|
// RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|
// MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
|
|
|
|
|
// body.add("uploadfile", new MultipartInputStreamFileResource(file.getInputStream(), file.getOriginalFilename()));
|
|
|
|
|
//
|
|
|
|
|
// HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
// headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
|
|
|
|
//
|
|
|
|
|
// HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
|
|
|
|
|
//
|
|
|
|
|
// String fullUrl = kubeflowBaseUrl + kubeflowApi;
|
|
|
|
|
// ResponseEntity<String> kubeflowResponse = restTemplate.postForEntity(fullUrl, requestEntity, String.class);
|
|
|
|
|
//
|
|
|
|
|
// response.put("kubeflowResponse", kubeflowResponse.getBody());
|
|
|
|
|
//
|
|
|
|
|
// return ResponseEntity.ok(response);
|
|
|
|
|
//
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// log.error("파일 업로드 실패", e);
|
|
|
|
|
// response.put("error", e.getMessage());
|
|
|
|
|
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
@Operation(summary = "파일 업로드 및 Kubeflow 업로드",
|
|
|
|
|
description = "MinIO와 DB에 저장하고 Kubeflow REST API에도 업로드합니다. Kubeflow API 경로는 요청 시 지정 가능")
|
|
|
|
|
@PostMapping(value = "/upload-and-kubeflow", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
|
|
|
|
public ResponseEntity<Map<String, Object>> uploadFileAndKubeflow(
|
|
|
|
|
@Parameter(description = "업로드할 파일") @RequestPart("file") MultipartFile file,
|
|
|
|
|
@RequestPart(value = "path", required = false) String path,
|
|
|
|
|
@RequestParam(value = "refId", required = false) Long refId,
|
|
|
|
|
@RequestParam(value = "refType", required = false, defaultValue = "TRAINING_SCRIPT") String refType,
|
|
|
|
|
@RequestParam(value = "title", required = false) String title,
|
|
|
|
|
@RequestParam(value = "description", required = false) String description,
|
|
|
|
|
@RequestParam(value = "version", required = false, defaultValue = "1") Integer version,
|
|
|
|
|
@RequestParam(value = "regUserId") String regUserId,
|
|
|
|
|
@RequestParam(value = "projectId") Long projectId,
|
|
|
|
|
@RequestParam(value = "kubeflowApi") String kubeflowApi
|
|
|
|
|
) {
|
|
|
|
|
Map<String, Object> response = new HashMap<>();
|
|
|
|
|
try {
|
|
|
|
|
MinioAttachmentEntity saved = minioAttachmentService.uploadFile(
|
|
|
|
|
file, path, refId, refType, title, description, version, regUserId, projectId
|
|
|
|
|
);
|
|
|
|
|
String minioUrl = minioAttachmentService.getFileUrl(saved.getStoragePath());
|
|
|
|
|
response.put("attachment", saved);
|
|
|
|
|
response.put("minioUrl", minioUrl);
|
|
|
|
|
|
|
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
|
|
|
|
|
body.add("uploadfile", new MultipartInputStreamFileResource(file.getInputStream(), file.getOriginalFilename()));
|
|
|
|
|
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
|
|
|
|
|
|
|
|
|
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
|
|
|
|
|
|
|
|
|
|
String fullUrl = kubeflowBaseUrl + kubeflowApi;
|
|
|
|
|
ResponseEntity<String> kubeflowResponse = restTemplate.postForEntity(fullUrl, requestEntity, String.class);
|
|
|
|
|
|
|
|
|
|
response.put("kubeflowResponse", kubeflowResponse.getBody());
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok(response);
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("파일 업로드 실패", e);
|
|
|
|
|
response.put("error", e.getMessage());
|
|
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 파일 업로드용 InputStreamResource
|
|
|
|
|
private static class MultipartInputStreamFileResource extends InputStreamResource {
|
|
|
|
|
|