Merge remote-tracking branch 'refs/remotes/origin/dev'
This commit is contained in:
@@ -2,19 +2,31 @@ package com.schisandra.oss.application.controller;
|
|||||||
|
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.amazonaws.util.IOUtils;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.schisandra.oss.application.convert.SchisandraOssMinioDTOConverter;
|
import com.schisandra.oss.application.convert.SchisandraOssMinioDTOConverter;
|
||||||
import com.schisandra.oss.application.dto.SchisandraOssMinioDTO;
|
import com.schisandra.oss.application.dto.SchisandraOssMinioDTO;
|
||||||
import com.schisandra.oss.application.oss.core.minio.MinioOssClient;
|
import com.schisandra.oss.application.oss.core.minio.MinioOssClient;
|
||||||
import com.schisandra.oss.application.oss.core.minio.MinioOssConfiguration;
|
import com.schisandra.oss.application.oss.core.minio.MinioOssConfiguration;
|
||||||
|
import com.schisandra.oss.application.oss.core.minio.model.MinioOssConfig;
|
||||||
|
import com.schisandra.oss.application.oss.model.OssInfo;
|
||||||
import com.schisandra.oss.common.entity.Result;
|
import com.schisandra.oss.common.entity.Result;
|
||||||
import com.schisandra.oss.domain.redis.RedisUtil;
|
|
||||||
import com.schisandra.oss.domain.bo.SchisandraOssMinioBO;
|
import com.schisandra.oss.domain.bo.SchisandraOssMinioBO;
|
||||||
|
import com.schisandra.oss.domain.redis.RedisUtil;
|
||||||
import com.schisandra.oss.domain.service.SchisandraOssMinioDomainService;
|
import com.schisandra.oss.domain.service.SchisandraOssMinioDomainService;
|
||||||
|
import io.minio.errors.*;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.ServletOutputStream;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.security.InvalidKeyException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,7 +72,214 @@ public class SchisandraOssMinioController {
|
|||||||
log.error("用户: {}-> minio 初始化完成!", userId);
|
log.error("用户: {}-> minio 初始化完成!", userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @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)));
|
||||||
@@ -146,6 +365,11 @@ public class SchisandraOssMinioController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void parameterCheck(SchisandraOssMinioDTO schisandraOssMinioDTO) {
|
private void parameterCheck(SchisandraOssMinioDTO schisandraOssMinioDTO) {
|
||||||
Preconditions.checkNotNull(schisandraOssMinioDTO.getId(), "不能为空");
|
Preconditions.checkNotNull(schisandraOssMinioDTO.getId(), "不能为空");
|
||||||
Preconditions.checkNotNull(schisandraOssMinioDTO.getUserId(), "不能为空");
|
Preconditions.checkNotNull(schisandraOssMinioDTO.getUserId(), "不能为空");
|
||||||
|
@@ -58,7 +58,7 @@ public class JdOssClient implements StandardOssClient {
|
|||||||
private JdOssConfig jdOssConfig;
|
private JdOssConfig jdOssConfig;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OssInfo upLoad(InputStream is, String targetName, Boolean isOverride) {
|
public OssInfo upLoad(InputStream is, String targetName,Boolean isOverride) {
|
||||||
String bucketName = getBucket();
|
String bucketName = getBucket();
|
||||||
String key = getKey(targetName, false);
|
String key = getKey(targetName, false);
|
||||||
|
|
||||||
|
@@ -58,7 +58,7 @@ public class JinShanOssClient implements StandardOssClient {
|
|||||||
private JinShanOssConfig jinShanOssConfig;
|
private JinShanOssConfig jinShanOssConfig;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OssInfo upLoad(InputStream is, String targetName, Boolean isOverride) {
|
public OssInfo upLoad(InputStream is, String targetName,Boolean isOverride) {
|
||||||
String bucket = getBucket();
|
String bucket = getBucket();
|
||||||
String key = getKey(targetName, false);
|
String key = getKey(targetName, false);
|
||||||
if (isOverride || !ks3.objectExists(bucket, key)) {
|
if (isOverride || !ks3.objectExists(bucket, key)) {
|
||||||
|
@@ -6,11 +6,12 @@ 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;
|
||||||
|
import com.alibaba.druid.util.StringUtils;
|
||||||
import com.aliyun.oss.common.utils.HttpHeaders;
|
import com.aliyun.oss.common.utils.HttpHeaders;
|
||||||
import com.google.common.io.ByteStreams;
|
|
||||||
import com.schisandra.oss.application.oss.constant.OssConstant;
|
import com.schisandra.oss.application.oss.constant.OssConstant;
|
||||||
import com.schisandra.oss.application.oss.core.StandardOssClient;
|
import com.schisandra.oss.application.oss.core.StandardOssClient;
|
||||||
import com.schisandra.oss.application.oss.core.minio.model.MinioOssConfig;
|
import com.schisandra.oss.application.oss.core.minio.model.MinioOssConfig;
|
||||||
@@ -22,6 +23,9 @@ import com.schisandra.oss.application.oss.model.download.DownloadCheckPoint;
|
|||||||
import com.schisandra.oss.application.oss.model.download.DownloadObjectStat;
|
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.http.Method;
|
||||||
|
import io.minio.messages.Bucket;
|
||||||
import io.minio.messages.Item;
|
import io.minio.messages.Item;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -31,9 +35,13 @@ import okhttp3.Headers;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.security.InvalidKeyException;
|
||||||
|
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
|
||||||
@@ -55,6 +63,138 @@ public class MinioOssClient implements StandardOssClient {
|
|||||||
private MinioClient minioClient;
|
private MinioClient minioClient;
|
||||||
private MinioOssConfig minioOssConfig;
|
private MinioOssConfig minioOssConfig;
|
||||||
|
|
||||||
|
|
||||||
|
public MinioOssConfig getMinioOssConfig() {
|
||||||
|
return minioOssConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMinioOssConfig(MinioOssConfig minioOssConfig) {
|
||||||
|
this.minioOssConfig = minioOssConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 {
|
||||||
|
if (!minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build())) {
|
||||||
|
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
|
||||||
|
} else {
|
||||||
|
return "bucket already exists";
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return bucketName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String deleteBucket(String bucketName) {
|
||||||
|
try {
|
||||||
|
if (minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build())) {
|
||||||
|
minioClient.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build());
|
||||||
|
} else {
|
||||||
|
return "bucket not exists";
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return "success";
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String, String> selectAllBucket() throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
|
||||||
|
List<Bucket> list = minioClient.listBuckets();
|
||||||
|
HashMap<String, String> names = new HashMap<>();
|
||||||
|
list.forEach(bucket -> {
|
||||||
|
names.put(bucket.name(), getMinioBucketSize(bucket.name()));
|
||||||
|
});
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 获取目录文件信息
|
||||||
|
* @param: [bucket, dirName]
|
||||||
|
* @return: java.util.List<com.schisandra.oss.application.oss.model.OssInfo>
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/26 13:34
|
||||||
|
*/
|
||||||
|
public List<OssInfo> listDir(String bucket, String dirName) throws Exception {
|
||||||
|
Iterable<Result<Item>> results = null;
|
||||||
|
if (StringUtils.isEmpty(dirName)) {
|
||||||
|
results = minioClient.listObjects(
|
||||||
|
ListObjectsArgs.builder().bucket(bucket).recursive(false).build());
|
||||||
|
} else {
|
||||||
|
results = minioClient.listObjects(
|
||||||
|
ListObjectsArgs.builder().prefix(dirName).bucket(bucket).recursive(false).build());
|
||||||
|
}
|
||||||
|
List<OssInfo> infos = new ArrayList<>();
|
||||||
|
results.forEach(r -> {
|
||||||
|
OssInfo info = new OssInfo();
|
||||||
|
try {
|
||||||
|
Item item = r.get();
|
||||||
|
if (item.isDir()) {
|
||||||
|
String[] directories = item.objectName().split("/");
|
||||||
|
info.setName(directories[directories.length - 1]);
|
||||||
|
info.setPath(item.objectName());
|
||||||
|
info.setIsDir(item.isDir());
|
||||||
|
} else {
|
||||||
|
String[] files = item.objectName().split("/");
|
||||||
|
info.setName(files[files.length - 1]);
|
||||||
|
info.setPath(item.objectName());
|
||||||
|
info.setIsDir(item.isDir());
|
||||||
|
info.setLength(String.valueOf(item.size()));
|
||||||
|
info.setCreateTime(String.valueOf(item.lastModified()));
|
||||||
|
}
|
||||||
|
infos.add(info);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return infos;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OssInfo upLoad(InputStream is, String targetName, Boolean isOverride) {
|
public OssInfo upLoad(InputStream is, String targetName, Boolean isOverride) {
|
||||||
try {
|
try {
|
||||||
@@ -68,7 +208,7 @@ public class MinioOssClient implements StandardOssClient {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new OssException(e);
|
throw new OssException(e);
|
||||||
}
|
}
|
||||||
return getInfo(targetName);
|
return getBaseInfo(targetName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -85,12 +225,13 @@ public class MinioOssClient implements StandardOssClient {
|
|||||||
public void downLoad(OutputStream os, String targetName) {
|
public void downLoad(OutputStream os, String targetName) {
|
||||||
GetObjectResponse is = null;
|
GetObjectResponse is = null;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
GetObjectArgs getObjectArgs = GetObjectArgs.builder()
|
GetObjectArgs getObjectArgs = GetObjectArgs.builder()
|
||||||
.bucket(getBucket())
|
.bucket(getBucket())
|
||||||
.object(getKey(targetName, true))
|
.object(getKey(targetName, true))
|
||||||
.build();
|
.build();
|
||||||
is = minioClient.getObject(getObjectArgs);
|
is = minioClient.getObject(getObjectArgs);
|
||||||
ByteStreams.copy(is, os);
|
IoUtil.copy(is, os);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new OssException(e);
|
throw new OssException(e);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -185,6 +326,13 @@ public class MinioOssClient implements StandardOssClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public InputStream getMinioObject(String bucket, String dirName) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
|
||||||
|
InputStream stream = minioClient.getObject(
|
||||||
|
GetObjectArgs.builder().bucket(bucket).object(dirName).build());
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OssInfo getInfo(String targetName, Boolean isRecursion) {
|
public OssInfo getInfo(String targetName, Boolean isRecursion) {
|
||||||
try {
|
try {
|
||||||
@@ -278,4 +426,5 @@ public class MinioOssClient implements StandardOssClient {
|
|||||||
return ossInfo;
|
return ossInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -14,6 +14,10 @@ public class OssInfo {
|
|||||||
* 名称
|
* 名称
|
||||||
*/
|
*/
|
||||||
private String name;
|
private String name;
|
||||||
|
/**
|
||||||
|
* 是否是文件夹
|
||||||
|
*/
|
||||||
|
private Boolean isDir;
|
||||||
/**
|
/**
|
||||||
* 存储路径
|
* 存储路径
|
||||||
*/
|
*/
|
||||||
|
@@ -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