|
@@ -1,52 +0,0 @@
|
|
|
-package com.css.simulation.resource.scheduler.controller;
|
|
|
-
|
|
|
-import api.common.pojo.param.MinioParameter;
|
|
|
-import api.common.util.FileUtil;
|
|
|
-import com.css.simulation.resource.scheduler.util.MinioUtil;
|
|
|
-import io.minio.MinioClient;
|
|
|
-import io.minio.errors.*;
|
|
|
-import lombok.SneakyThrows;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.http.MediaType;
|
|
|
-import org.springframework.validation.annotation.Validated;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
-
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.InputStream;
|
|
|
-import java.security.InvalidKeyException;
|
|
|
-import java.security.NoSuchAlgorithmException;
|
|
|
-
|
|
|
-@RequestMapping("/minio")
|
|
|
-@RestController
|
|
|
-@Slf4j
|
|
|
-public class MinioController {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- MinioClient minioClient;
|
|
|
-
|
|
|
- private static final String BUCKET_NAME = "test";
|
|
|
-
|
|
|
-
|
|
|
- @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
|
|
- @SneakyThrows
|
|
|
- public void upload(@RequestPart("file") MultipartFile file, String path) {
|
|
|
- MinioUtil.uploadFromMultipartFile(minioClient, file, BUCKET_NAME, path);
|
|
|
- }
|
|
|
-
|
|
|
- @PostMapping("/download")
|
|
|
- public void download(
|
|
|
- @RequestBody @Validated MinioParameter minioParameter,
|
|
|
- HttpServletResponse response
|
|
|
- ) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
|
|
|
- InputStream inputStream = MinioUtil.downloadToStream(
|
|
|
- minioClient,
|
|
|
- BUCKET_NAME,
|
|
|
- minioParameter.getObjectName()
|
|
|
- );
|
|
|
- String fileName = FileUtil.getFileName(minioParameter.getObjectName());
|
|
|
- FileUtil.downloadForHttp(fileName, inputStream, response, 4096);
|
|
|
- }
|
|
|
-}
|