fix: minio存储桶的增删改查,数据的增删改查
This commit is contained in:
@@ -72,7 +72,214 @@ public class SchisandraOssMinioController {
|
|||||||
log.error("用户: " + userId + "-> minio 初始化完成!");
|
log.error("用户: " + userId + "-> minio 初始化完成!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @description: 获取文件目录信息
|
||||||
|
* @param: [target, userId, dirName]
|
||||||
|
* @return: com.schisandra.oss.common.entity.Result<java.lang.String>
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/26 13:55
|
||||||
|
*/
|
||||||
|
@GetMapping("listMinioDir")
|
||||||
|
public Result<String> listMinioInfo(@RequestParam String target, @RequestParam String userId, @RequestParam String dirName,@RequestParam String bucket) throws Exception {
|
||||||
|
Preconditions.checkNotNull(target, "不能为空");
|
||||||
|
Preconditions.checkNotNull(userId, "不能为空");
|
||||||
|
MinioOssClient bean = SpringUtil.getBean(userId);
|
||||||
|
bean.getMinioOssConfig().setBucketName(bucket);
|
||||||
|
return Result.ok(bean.listDir(target, dirName));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 下载文件
|
||||||
|
* @param: [schisandraOssMinioDTO]
|
||||||
|
* @return: void
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/26 13:56
|
||||||
|
*/
|
||||||
|
@GetMapping("downloadMinioFile")
|
||||||
|
public void getMinioFile(@RequestParam String bucket, @RequestParam String userId, @RequestParam String filePath, HttpServletResponse response) throws Exception {
|
||||||
|
Preconditions.checkNotNull(bucket, "不能为空");
|
||||||
|
Preconditions.checkNotNull(userId, "不能为空");
|
||||||
|
Preconditions.checkNotNull(filePath, "不能为空");
|
||||||
|
MinioOssClient bean = SpringUtil.getBean(userId);
|
||||||
|
bean.getMinioOssConfig().setBucketName(bucket);
|
||||||
|
InputStream stream = bean.getMinioObject(bucket, filePath);
|
||||||
|
ServletOutputStream output = response.getOutputStream();
|
||||||
|
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filePath.substring(filePath.lastIndexOf("/") + 1), "UTF-8"));
|
||||||
|
response.setContentType("application/octet-stream");
|
||||||
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
IOUtils.copy(stream, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 删除文件
|
||||||
|
* @param: [schisandraOssMinioDTO]
|
||||||
|
* @return: void
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/26 14:34
|
||||||
|
*/
|
||||||
|
@PostMapping("deleteMinioFile")
|
||||||
|
public Result deleteMinioFile(@RequestParam String bucket, @RequestParam String userId, @RequestParam String filePath) {
|
||||||
|
Preconditions.checkNotNull(bucket, "不能为空");
|
||||||
|
Preconditions.checkNotNull(userId, "不能为空");
|
||||||
|
Preconditions.checkNotNull(filePath, "不能为空");
|
||||||
|
MinioOssClient bean = SpringUtil.getBean(userId);
|
||||||
|
bean.getMinioOssConfig().setBucketName(bucket);
|
||||||
|
bean.delete(filePath);
|
||||||
|
return Result.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 上传文件
|
||||||
|
* @param: [schisandraOssMinioDTO]
|
||||||
|
* @return: void
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/26 14:34
|
||||||
|
*/
|
||||||
|
@PostMapping("uploadMinioFile")
|
||||||
|
public Result<OssInfo> uploadMinioFile(@RequestParam String userId, @RequestParam MultipartFile file, @RequestParam String fileName, @RequestParam String bucket) throws IOException {
|
||||||
|
Preconditions.checkNotNull(userId, "不能为空");
|
||||||
|
Preconditions.checkNotNull(fileName, "不能为空");
|
||||||
|
Preconditions.checkNotNull(bucket, "不能为空");
|
||||||
|
// 获取文件输入流
|
||||||
|
InputStream is = file.getInputStream();
|
||||||
|
MinioOssClient bean = SpringUtil.getBean(userId);
|
||||||
|
bean.getMinioOssConfig().setBucketName(bucket);
|
||||||
|
return Result.ok(bean.upLoad(is, fileName, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 重命名文件
|
||||||
|
* @param: [userId, bucket, oldFileName, newFileName]
|
||||||
|
* @return: com.schisandra.oss.common.entity.Result
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/27 9:41
|
||||||
|
*/
|
||||||
|
@PostMapping("renameMinioFile")
|
||||||
|
public Result renameMinioFile(@RequestParam String userId, @RequestParam String bucket, @RequestParam String oldFileName, @RequestParam String newFileName) throws IOException {
|
||||||
|
|
||||||
|
Preconditions.checkNotNull(userId, "不能为空");
|
||||||
|
Preconditions.checkNotNull(bucket, "不能为空");
|
||||||
|
Preconditions.checkNotNull(oldFileName, "不能为空");
|
||||||
|
Preconditions.checkNotNull(newFileName, "不能为空");
|
||||||
|
MinioOssClient bean = SpringUtil.getBean(userId);
|
||||||
|
bean.getMinioOssConfig().setBucketName(bucket);
|
||||||
|
try {
|
||||||
|
bean.rename(oldFileName, newFileName);
|
||||||
|
}catch (Exception e){
|
||||||
|
return Result.fail(e.getMessage());
|
||||||
|
}
|
||||||
|
return Result.ok();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @description: 拷贝文件
|
||||||
|
* @param: [userId, bucket, oldFilePath, newFilePath]
|
||||||
|
* @return: com.schisandra.oss.common.entity.Result
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/27 9:52
|
||||||
|
*/
|
||||||
|
@PostMapping("copyMinioFile")
|
||||||
|
public Result copyMinioFile(@RequestParam String userId, @RequestParam String bucket, @RequestParam String oldFilePath, @RequestParam String newFilePath) throws IOException {
|
||||||
|
|
||||||
|
Preconditions.checkNotNull(userId, "不能为空");
|
||||||
|
Preconditions.checkNotNull(bucket, "不能为空");
|
||||||
|
Preconditions.checkNotNull(oldFilePath, "不能为空");
|
||||||
|
Preconditions.checkNotNull(newFilePath, "不能为空");
|
||||||
|
MinioOssClient bean = SpringUtil.getBean(userId);
|
||||||
|
bean.getMinioOssConfig().setBucketName(bucket);
|
||||||
|
try {
|
||||||
|
bean.copy(oldFilePath, newFilePath);
|
||||||
|
}catch (Exception e){
|
||||||
|
return Result.fail(e.getMessage());
|
||||||
|
}
|
||||||
|
return Result.ok();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @description: 预览文件
|
||||||
|
* @param: [userId, bucket, filePath]
|
||||||
|
* @return: com.schisandra.oss.common.entity.Result<java.lang.String>
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/27 10:14
|
||||||
|
*/
|
||||||
|
@PostMapping("previewMinioFile")
|
||||||
|
public Result<String> previewMinioFile(@RequestParam String userId, @RequestParam String bucket, @RequestParam String filePath) throws IOException {
|
||||||
|
Preconditions.checkNotNull(userId, "不能为空");
|
||||||
|
Preconditions.checkNotNull(bucket, "不能为空");
|
||||||
|
Preconditions.checkNotNull(filePath, "不能为空");
|
||||||
|
MinioOssClient bean = SpringUtil.getBean(userId);
|
||||||
|
bean.getMinioOssConfig().setBucketName(bucket);
|
||||||
|
try {
|
||||||
|
return Result.ok(bean.getMinioPreviewUrl(filePath));
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Result.fail(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @description: 分享文件
|
||||||
|
* @param: [userId, bucket, filePath]
|
||||||
|
* @return: com.schisandra.oss.common.entity.Result<java.lang.String>
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/27 10:17
|
||||||
|
*/
|
||||||
|
@PostMapping("shareMinioFile")
|
||||||
|
public Result<String> shareMinioFile(@RequestParam String userId, @RequestParam String bucket, @RequestParam String filePath, @RequestParam int time) throws IOException {
|
||||||
|
Preconditions.checkNotNull(userId, "不能为空");
|
||||||
|
Preconditions.checkNotNull(bucket, "不能为空");
|
||||||
|
Preconditions.checkNotNull(filePath, "不能为空");
|
||||||
|
MinioOssClient bean = SpringUtil.getBean(userId);
|
||||||
|
bean.getMinioOssConfig().setBucketName(bucket);
|
||||||
|
try {
|
||||||
|
return Result.ok(bean.shareMinioFile(filePath,time));
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Result.fail(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 获取所有bucket
|
||||||
|
* @param: [userId, bucket]
|
||||||
|
* @return: com.schisandra.oss.common.entity.Result<java.lang.String>
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/26 17:37
|
||||||
|
*/
|
||||||
|
@PostMapping("seleteBucket")
|
||||||
|
public Result<String> seleteBucket(@RequestParam String userId) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
|
||||||
|
Preconditions.checkNotNull(userId, "不能为空");
|
||||||
|
MinioOssClient bean = SpringUtil.getBean(userId);
|
||||||
|
return Result.ok(bean.selectAllBucket());
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @description: 创建bucket
|
||||||
|
* @param: [userId, bucket]
|
||||||
|
* @return: com.schisandra.oss.common.entity.Result<java.lang.String>
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/26 17:38
|
||||||
|
*/
|
||||||
|
@PostMapping("createBucket")
|
||||||
|
public Result<String> createBucket(@RequestParam String userId, @RequestParam String bucket) {
|
||||||
|
Preconditions.checkNotNull(userId, "不能为空");
|
||||||
|
Preconditions.checkNotNull(bucket, "不能为空");
|
||||||
|
MinioOssClient bean = SpringUtil.getBean(userId);
|
||||||
|
bean.getMinioOssConfig().setBucketName(bucket);
|
||||||
|
return Result.ok(bean.createBucket(bucket));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 删除bucket
|
||||||
|
* @param: [userId, bucket]
|
||||||
|
* @return: com.schisandra.oss.common.entity.Result<java.lang.String>
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/26 17:38
|
||||||
|
*/
|
||||||
|
@PostMapping("deleteBucket")
|
||||||
|
public Result<String> deleteBucket(@RequestParam String userId, @RequestParam String bucket) {
|
||||||
|
Preconditions.checkNotNull(userId, "不能为空");
|
||||||
|
Preconditions.checkNotNull(bucket, "不能为空");
|
||||||
|
MinioOssClient bean = SpringUtil.getBean(userId);
|
||||||
|
bean.getMinioOssConfig().setBucketName(bucket);
|
||||||
|
return Result.ok(bean.deleteBucket(bucket));
|
||||||
|
}
|
||||||
@PostMapping("get")
|
@PostMapping("get")
|
||||||
public SchisandraOssMinioDTO getMinioOss(@RequestParam String userId) {
|
public SchisandraOssMinioDTO getMinioOss(@RequestParam String userId) {
|
||||||
return SchisandraOssMinioDTOConverter.INSTANCE.convertBOToDTO(schisandraOssMinioDomainService.getMinioConfig(Long.valueOf(userId)));
|
return SchisandraOssMinioDTOConverter.INSTANCE.convertBOToDTO(schisandraOssMinioDomainService.getMinioConfig(Long.valueOf(userId)));
|
||||||
@@ -157,124 +364,8 @@ public class SchisandraOssMinioController {
|
|||||||
return Result.ok(schisandraOssMinioDTOS);
|
return Result.ok(schisandraOssMinioDTOS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @description: 获取文件目录信息
|
|
||||||
* @param: [target, userId, dirName]
|
|
||||||
* @return: com.schisandra.oss.common.entity.Result<java.lang.String>
|
|
||||||
* @author zlg
|
|
||||||
* @date: 2024/6/26 13:55
|
|
||||||
*/
|
|
||||||
@GetMapping("listMinioDir")
|
|
||||||
public Result<String> listMinioInfo(@RequestParam String target, @RequestParam String userId, @RequestParam String dirName,@RequestParam String bucket) throws Exception {
|
|
||||||
Preconditions.checkNotNull(target, "不能为空");
|
|
||||||
Preconditions.checkNotNull(userId, "不能为空");
|
|
||||||
MinioOssClient bean = SpringUtil.getBean(userId);
|
|
||||||
bean.getMinioOssConfig().setBucketName(bucket);
|
|
||||||
return Result.ok(bean.listDir(target, dirName));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description: 下载文件
|
|
||||||
* @param: [schisandraOssMinioDTO]
|
|
||||||
* @return: void
|
|
||||||
* @author zlg
|
|
||||||
* @date: 2024/6/26 13:56
|
|
||||||
*/
|
|
||||||
@GetMapping("downloadMinioFile")
|
|
||||||
public void getMinioFile(@RequestParam String bucket, @RequestParam String userId, @RequestParam String filePath, HttpServletResponse response) throws Exception {
|
|
||||||
Preconditions.checkNotNull(bucket, "不能为空");
|
|
||||||
Preconditions.checkNotNull(userId, "不能为空");
|
|
||||||
Preconditions.checkNotNull(filePath, "不能为空");
|
|
||||||
MinioOssClient bean = SpringUtil.getBean(userId);
|
|
||||||
bean.getMinioOssConfig().setBucketName(bucket);
|
|
||||||
InputStream stream = bean.getMinioObject(bucket, filePath);
|
|
||||||
ServletOutputStream output = response.getOutputStream();
|
|
||||||
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filePath.substring(filePath.lastIndexOf("/") + 1), "UTF-8"));
|
|
||||||
response.setContentType("application/octet-stream");
|
|
||||||
response.setCharacterEncoding("UTF-8");
|
|
||||||
IOUtils.copy(stream, output);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description: 删除文件
|
|
||||||
* @param: [schisandraOssMinioDTO]
|
|
||||||
* @return: void
|
|
||||||
* @author zlg
|
|
||||||
* @date: 2024/6/26 14:34
|
|
||||||
*/
|
|
||||||
@PostMapping("deleteMinioFile")
|
|
||||||
public Result deleteMinioFile(@RequestParam String bucket, @RequestParam String userId, @RequestParam String filePath) {
|
|
||||||
Preconditions.checkNotNull(bucket, "不能为空");
|
|
||||||
Preconditions.checkNotNull(userId, "不能为空");
|
|
||||||
Preconditions.checkNotNull(filePath, "不能为空");
|
|
||||||
MinioOssClient bean = SpringUtil.getBean(userId);
|
|
||||||
bean.getMinioOssConfig().setBucketName(bucket);
|
|
||||||
bean.delete(filePath);
|
|
||||||
return Result.ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description: 上传文件
|
|
||||||
* @param: [schisandraOssMinioDTO]
|
|
||||||
* @return: void
|
|
||||||
* @author zlg
|
|
||||||
* @date: 2024/6/26 14:34
|
|
||||||
*/
|
|
||||||
@PostMapping("uploadMinioFile")
|
|
||||||
public Result<OssInfo> uploadMinioFile(@RequestParam String userId, @RequestParam MultipartFile file, @RequestParam String fileName, @RequestParam String bucket) throws IOException {
|
|
||||||
Preconditions.checkNotNull(userId, "不能为空");
|
|
||||||
Preconditions.checkNotNull(fileName, "不能为空");
|
|
||||||
Preconditions.checkNotNull(bucket, "不能为空");
|
|
||||||
// 获取文件输入流
|
|
||||||
InputStream is = file.getInputStream();
|
|
||||||
MinioOssClient bean = SpringUtil.getBean(userId);
|
|
||||||
bean.getMinioOssConfig().setBucketName(bucket);
|
|
||||||
return Result.ok(bean.upLoad(is, fileName, true));
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @description: 获取所有bucket
|
|
||||||
* @param: [userId, bucket]
|
|
||||||
* @return: com.schisandra.oss.common.entity.Result<java.lang.String>
|
|
||||||
* @author zlg
|
|
||||||
* @date: 2024/6/26 17:37
|
|
||||||
*/
|
|
||||||
@PostMapping("seleteBucket")
|
|
||||||
public Result<String> seleteBucket(@RequestParam String userId) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
|
|
||||||
Preconditions.checkNotNull(userId, "不能为空");
|
|
||||||
MinioOssClient bean = SpringUtil.getBean(userId);
|
|
||||||
return Result.ok(bean.selectAllBucket());
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @description: 创建bucket
|
|
||||||
* @param: [userId, bucket]
|
|
||||||
* @return: com.schisandra.oss.common.entity.Result<java.lang.String>
|
|
||||||
* @author zlg
|
|
||||||
* @date: 2024/6/26 17:38
|
|
||||||
*/
|
|
||||||
@PostMapping("createBucket")
|
|
||||||
public Result<String> createBucket(@RequestParam String userId, @RequestParam String bucket) {
|
|
||||||
Preconditions.checkNotNull(userId, "不能为空");
|
|
||||||
Preconditions.checkNotNull(bucket, "不能为空");
|
|
||||||
MinioOssClient bean = SpringUtil.getBean(userId);
|
|
||||||
bean.getMinioOssConfig().setBucketName(bucket);
|
|
||||||
return Result.ok(bean.createBucket(bucket));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description: 删除bucket
|
|
||||||
* @param: [userId, bucket]
|
|
||||||
* @return: com.schisandra.oss.common.entity.Result<java.lang.String>
|
|
||||||
* @author zlg
|
|
||||||
* @date: 2024/6/26 17:38
|
|
||||||
*/
|
|
||||||
@PostMapping("deleteBucket")
|
|
||||||
public Result<String> deleteBucket(@RequestParam String userId, @RequestParam String bucket) {
|
|
||||||
Preconditions.checkNotNull(userId, "不能为空");
|
|
||||||
Preconditions.checkNotNull(bucket, "不能为空");
|
|
||||||
MinioOssClient bean = SpringUtil.getBean(userId);
|
|
||||||
bean.getMinioOssConfig().setBucketName(bucket);
|
|
||||||
return Result.ok(bean.deleteBucket(bucket));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -6,6 +6,7 @@ import cn.hutool.core.date.DateUtil;
|
|||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.io.file.FileNameUtil;
|
import cn.hutool.core.io.file.FileNameUtil;
|
||||||
|
import cn.hutool.core.io.unit.DataSizeUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.ReflectUtil;
|
import cn.hutool.core.util.ReflectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
@@ -23,6 +24,7 @@ import com.schisandra.oss.application.oss.model.download.DownloadObjectStat;
|
|||||||
import com.schisandra.oss.application.oss.utils.OssPathUtil;
|
import com.schisandra.oss.application.oss.utils.OssPathUtil;
|
||||||
import io.minio.*;
|
import io.minio.*;
|
||||||
import io.minio.errors.*;
|
import io.minio.errors.*;
|
||||||
|
import io.minio.http.Method;
|
||||||
import io.minio.messages.Bucket;
|
import io.minio.messages.Bucket;
|
||||||
import io.minio.messages.Item;
|
import io.minio.messages.Item;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@@ -39,6 +41,7 @@ import java.io.OutputStream;
|
|||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* http://docs.minio.org.cn/docs/master/minio-monitoring-guide
|
* http://docs.minio.org.cn/docs/master/minio-monitoring-guide
|
||||||
@@ -61,7 +64,6 @@ public class MinioOssClient implements StandardOssClient {
|
|||||||
private MinioOssConfig minioOssConfig;
|
private MinioOssConfig minioOssConfig;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public MinioOssConfig getMinioOssConfig() {
|
public MinioOssConfig getMinioOssConfig() {
|
||||||
return minioOssConfig;
|
return minioOssConfig;
|
||||||
}
|
}
|
||||||
@@ -69,12 +71,58 @@ public class MinioOssClient implements StandardOssClient {
|
|||||||
public void setMinioOssConfig(MinioOssConfig minioOssConfig) {
|
public void setMinioOssConfig(MinioOssConfig minioOssConfig) {
|
||||||
this.minioOssConfig = minioOssConfig;
|
this.minioOssConfig = minioOssConfig;
|
||||||
}
|
}
|
||||||
public String createBucket(String bucketName) {
|
|
||||||
|
|
||||||
|
|
||||||
|
public String getMinioBucketSize(String bucket) {
|
||||||
|
Iterable<Result<Item>> results =
|
||||||
|
minioClient.listObjects(
|
||||||
|
ListObjectsArgs.builder().bucket(bucket).recursive(true).build());
|
||||||
|
final long[] totalSize = {0};
|
||||||
|
final Item[] item = {null};
|
||||||
|
results.forEach(result -> {
|
||||||
|
try {
|
||||||
|
item[0] = result.get();
|
||||||
|
totalSize[0] = item[0].size() + totalSize[0];
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("listObjects error", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return String.valueOf(DataSizeUtil.format(totalSize[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMinioPreviewUrl(String fileName) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
|
||||||
|
String presignedUrl = null;
|
||||||
|
presignedUrl = minioClient.getPresignedObjectUrl(
|
||||||
|
GetPresignedObjectUrlArgs.builder()
|
||||||
|
.method(Method.GET)
|
||||||
|
.bucket(getBucket())
|
||||||
|
.object(fileName)
|
||||||
|
.expiry(1, TimeUnit.DAYS)
|
||||||
|
.build());
|
||||||
|
return presignedUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String shareMinioFile(String fileName, int time) {
|
||||||
|
String presignedUrl = null;
|
||||||
|
try {
|
||||||
|
presignedUrl = minioClient.getPresignedObjectUrl(
|
||||||
|
GetPresignedObjectUrlArgs.builder()
|
||||||
|
.method(Method.GET)
|
||||||
|
.bucket(getBucket())
|
||||||
|
.object(fileName)
|
||||||
|
.expiry(time)
|
||||||
|
.build());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return presignedUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String createBucket(String bucketName) {
|
||||||
try {
|
try {
|
||||||
if (!minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build())) {
|
if (!minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build())) {
|
||||||
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
|
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
|
||||||
}else {
|
} else {
|
||||||
return "bucket already exists";
|
return "bucket already exists";
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -82,27 +130,29 @@ public class MinioOssClient implements StandardOssClient {
|
|||||||
}
|
}
|
||||||
return bucketName;
|
return bucketName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String deleteBucket(String bucketName) {
|
public String deleteBucket(String bucketName) {
|
||||||
try {
|
try {
|
||||||
if (minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build())){
|
if (minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build())) {
|
||||||
minioClient.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build());
|
minioClient.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build());
|
||||||
}else {
|
} else {
|
||||||
return "bucket not exists";
|
return "bucket not exists";
|
||||||
}
|
}
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return "success";
|
return "success";
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> selectAllBucket() throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
|
public HashMap<String, String> selectAllBucket() throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
|
||||||
List<Bucket> list = minioClient.listBuckets();
|
List<Bucket> list = minioClient.listBuckets();
|
||||||
List<String> names = new ArrayList<>();
|
HashMap<String, String> names = new HashMap<>();
|
||||||
list.forEach(bucket -> {
|
list.forEach(bucket -> {
|
||||||
names.add(bucket.name());
|
names.put(bucket.name(), getMinioBucketSize(bucket.name()));
|
||||||
});
|
});
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: 获取目录文件信息
|
* @description: 获取目录文件信息
|
||||||
* @param: [bucket, dirName]
|
* @param: [bucket, dirName]
|
||||||
@@ -144,6 +194,7 @@ public class MinioOssClient implements StandardOssClient {
|
|||||||
});
|
});
|
||||||
return infos;
|
return infos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OssInfo upLoad(InputStream is, String targetName, Boolean isOverride) {
|
public OssInfo upLoad(InputStream is, String targetName, Boolean isOverride) {
|
||||||
try {
|
try {
|
||||||
@@ -274,6 +325,7 @@ public class MinioOssClient implements StandardOssClient {
|
|||||||
throw new OssException(e);
|
throw new OssException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputStream getMinioObject(String bucket, String dirName) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
|
public InputStream getMinioObject(String bucket, String dirName) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
|
||||||
InputStream stream = minioClient.getObject(
|
InputStream stream = minioClient.getObject(
|
||||||
GetObjectArgs.builder().bucket(bucket).object(dirName).build());
|
GetObjectArgs.builder().bucket(bucket).object(dirName).build());
|
||||||
@@ -374,4 +426,5 @@ public class MinioOssClient implements StandardOssClient {
|
|||||||
return ossInfo;
|
return ossInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
<artifactId>schisandra-cloud-storage-oss-common</artifactId>
|
<artifactId>schisandra-cloud-storage-oss-common</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>schisandra-cloud-storage-oss-common</name>
|
<name>schisandra-cloud-storage-oss-common</name>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
@@ -124,11 +123,12 @@
|
|||||||
<artifactId>minio</artifactId>
|
<artifactId>minio</artifactId>
|
||||||
<version>8.2.1</version>
|
<version>8.2.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 阿里云 -->
|
<!-- 阿里云 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.aliyun.oss</groupId>
|
<groupId>com.aliyun.oss</groupId>
|
||||||
<artifactId>aliyun-sdk-oss</artifactId>
|
<artifactId>aliyun-sdk-oss</artifactId>
|
||||||
<version>3.14.0</version>
|
<version>3.17.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 亚马逊 -->
|
<!-- 亚马逊 -->
|
||||||
|
Reference in New Issue
Block a user