|
@@ -0,0 +1,119 @@
|
|
|
|
+//package com.css.simulation.resource.common.util;
|
|
|
|
+//
|
|
|
|
+//import io.minio.*;
|
|
|
|
+//import io.minio.errors.ErrorResponseException;
|
|
|
|
+//import io.minio.errors.InsufficientDataException;
|
|
|
|
+//import io.minio.errors.InvalidResponseException;
|
|
|
|
+//import io.minio.errors.XmlParserException;
|
|
|
|
+//import jdk.nashorn.internal.runtime.regexp.joni.exception.InternalException;
|
|
|
|
+//import org.springframework.web.multipart.MultipartFile;
|
|
|
|
+//
|
|
|
|
+//import java.io.IOException;
|
|
|
|
+//import java.io.InputStream;
|
|
|
|
+//import java.rmi.ServerException;
|
|
|
|
+//import java.security.InvalidKeyException;
|
|
|
|
+//import java.security.NoSuchAlgorithmException;
|
|
|
|
+//
|
|
|
|
+//public class MinioUtil {
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * 判断 bucket 是否存在
|
|
|
|
+// */
|
|
|
|
+// public static boolean isBucketExist(MinioClient minioClient, String bucketName) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException, io.minio.errors.ServerException, io.minio.errors.InternalException {
|
|
|
|
+// return minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * 创建 bucket
|
|
|
|
+// */
|
|
|
|
+// public static void createBucket(MinioClient minioClient, String bucketName) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException, io.minio.errors.ServerException, io.minio.errors.InternalException {
|
|
|
|
+// if (!isBucketExist(minioClient, bucketName)) {
|
|
|
|
+// minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * 通过文件路径上传文件上传文件
|
|
|
|
+// */
|
|
|
|
+// public static void uploadFromFile(
|
|
|
|
+// MinioClient minioClient,
|
|
|
|
+// String sourceFilePath,
|
|
|
|
+// String bucketName,
|
|
|
|
+// String objectName
|
|
|
|
+// ) throws IOException, InsufficientDataException, ErrorResponseException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException, io.minio.errors.ServerException, io.minio.errors.InternalException {
|
|
|
|
+// minioClient.uploadObject(UploadObjectArgs.builder()
|
|
|
|
+// .filename(sourceFilePath)
|
|
|
|
+// .bucket(bucketName)
|
|
|
|
+// .object(objectName)
|
|
|
|
+// .build());
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * 通过文件路径上传文件上传文件
|
|
|
|
+// *
|
|
|
|
+// * @param partSize 分片最小 5MB
|
|
|
|
+// */
|
|
|
|
+// public static void uploadFromStream(
|
|
|
|
+// MinioClient minioClient,
|
|
|
|
+// InputStream inputStream,
|
|
|
|
+// long objectSize,
|
|
|
|
+// long partSize,
|
|
|
|
+// String bucketName,
|
|
|
|
+// String objectName
|
|
|
|
+// ) throws IOException, InsufficientDataException, ErrorResponseException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException, io.minio.errors.ServerException, io.minio.errors.InternalException {
|
|
|
|
+// minioClient.putObject(PutObjectArgs.builder()
|
|
|
|
+// .stream(inputStream, objectSize, partSize)
|
|
|
|
+// .bucket(bucketName)
|
|
|
|
+// .object(objectName)
|
|
|
|
+// .build());
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * 通过文件路径上传文件上传文件
|
|
|
|
+// */
|
|
|
|
+// public static void uploadFromMultipartFile(
|
|
|
|
+// MinioClient minioClient,
|
|
|
|
+// MultipartFile multipartFile,
|
|
|
|
+// String bucketName,
|
|
|
|
+// String objectName
|
|
|
|
+// ) throws IOException, InsufficientDataException, ErrorResponseException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException, io.minio.errors.ServerException, io.minio.errors.InternalException {
|
|
|
|
+// InputStream inputStream = multipartFile.getInputStream();
|
|
|
|
+// long objectSize = multipartFile.getSize();
|
|
|
|
+// long partSize = 5 * 1024 * 1024L; // 分片最小 5M
|
|
|
|
+// minioClient.putObject(PutObjectArgs.builder()
|
|
|
|
+// .stream(inputStream, objectSize, partSize)
|
|
|
|
+// .bucket(bucketName)
|
|
|
|
+// .object(objectName)
|
|
|
|
+// .build());
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * 下载文件
|
|
|
|
+// */
|
|
|
|
+// public static void downloadToFile(
|
|
|
|
+// MinioClient minioClient,
|
|
|
|
+// String bucketName,
|
|
|
|
+// String objectName,
|
|
|
|
+// String targetFilePath
|
|
|
|
+// ) throws IOException, InsufficientDataException, ErrorResponseException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException, io.minio.errors.ServerException, io.minio.errors.InternalException {
|
|
|
|
+// minioClient.downloadObject(DownloadObjectArgs.builder()
|
|
|
|
+// .bucket(bucketName)
|
|
|
|
+// .object(objectName)
|
|
|
|
+// .filename(targetFilePath)
|
|
|
|
+// .build());
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * 下载文件
|
|
|
|
+// */
|
|
|
|
+// public static InputStream downloadToStream(
|
|
|
|
+// MinioClient minioClient,
|
|
|
|
+// String bucketName,
|
|
|
|
+// String objectName
|
|
|
|
+// ) throws IOException, InsufficientDataException, ErrorResponseException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException, io.minio.errors.ServerException, io.minio.errors.InternalException {
|
|
|
|
+// return minioClient.getObject(GetObjectArgs.builder()
|
|
|
|
+// .bucket(bucketName)
|
|
|
|
+// .object(objectName)
|
|
|
|
+// .build());
|
|
|
|
+// }
|
|
|
|
+//}
|