|
@@ -4,9 +4,7 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import com.persagy.dmp.common.exception.BusinessException;
|
|
|
import com.persagy.dmp.storage.constant.FileCommonConst;
|
|
|
import com.persagy.dmp.storage.service.IFileStorageService;
|
|
|
-import io.minio.MinioClient;
|
|
|
-import io.minio.ObjectStat;
|
|
|
-import io.minio.PutObjectOptions;
|
|
|
+import io.minio.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -35,8 +33,10 @@ public class MinioStorageServiceImpl implements IFileStorageService {
|
|
|
// 确认桶是否存在
|
|
|
bucketName = ensureBucket(bucketName);
|
|
|
// 上传文件
|
|
|
- PutObjectOptions options = new PutObjectOptions(input.available(), -1);
|
|
|
- minioClient.putObject(bucketName, fileName, input, options);
|
|
|
+// PutObjectOptions options = new PutObjectOptions(input.available(), -1);
|
|
|
+// minioClient.putObject(bucketName, fileName, input, options);
|
|
|
+ minioClient.putObject(PutObjectArgs.builder().bucket(bucketName).object(fileName).
|
|
|
+ stream(input, input.available(), -1).build());
|
|
|
} catch (Exception e) {
|
|
|
MinioExceptionHandler.handleException(e);
|
|
|
}
|
|
@@ -52,7 +52,8 @@ public class MinioStorageServiceImpl implements IFileStorageService {
|
|
|
// 确认桶是否存在
|
|
|
bucketName = ensureBucket(bucketName);
|
|
|
// 下载文件
|
|
|
- return minioClient.getObject(bucketName, fileName);
|
|
|
+// return minioClient.getObject(bucketName, fileName);
|
|
|
+ return minioClient.getObject(GetObjectArgs.builder().bucket(bucketName).object(fileName).build());
|
|
|
} catch (Exception e) {
|
|
|
MinioExceptionHandler.handleException(e);
|
|
|
}
|
|
@@ -69,7 +70,9 @@ public class MinioStorageServiceImpl implements IFileStorageService {
|
|
|
// 确认桶是否存在
|
|
|
bucketName = ensureBucket(bucketName);
|
|
|
// 下载文件
|
|
|
- return minioClient.presignedGetObject(bucketName, fileName, FileCommonConst.URL_EXPIRES);
|
|
|
+// return minioClient.presignedGetObject(bucketName, fileName, FileCommonConst.URL_EXPIRES);
|
|
|
+ return minioClient.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder()
|
|
|
+ .bucket(bucketName).object(fileName).expiry(FileCommonConst.URL_EXPIRES).build());
|
|
|
} catch (Exception e) {
|
|
|
MinioExceptionHandler.handleException(e);
|
|
|
}
|
|
@@ -86,7 +89,9 @@ public class MinioStorageServiceImpl implements IFileStorageService {
|
|
|
// 确认桶是否存在
|
|
|
bucketName = ensureBucket(bucketName);
|
|
|
// 查看文件元数据
|
|
|
- ObjectStat stat = minioClient.statObject(bucketName, fileName);
|
|
|
+// ObjectStat stat = minioClient.statObject(bucketName, fileName);
|
|
|
+// return stat != null;
|
|
|
+ StatObjectResponse stat = minioClient.statObject(StatObjectArgs.builder().bucket(bucketName).object(fileName).build());
|
|
|
return stat != null;
|
|
|
} catch (Exception e) {
|
|
|
MinioExceptionHandler.handleException(e);
|
|
@@ -104,7 +109,8 @@ public class MinioStorageServiceImpl implements IFileStorageService {
|
|
|
// 确认桶是否存在
|
|
|
bucketName = ensureBucket(bucketName);
|
|
|
// 删除文件
|
|
|
- minioClient.removeObject(bucketName, fileName);
|
|
|
+// minioClient.removeObject(bucketName, fileName);
|
|
|
+ minioClient.removeObject(RemoveObjectArgs.builder().bucket(bucketName).object(fileName).build());
|
|
|
} catch (Exception e) {
|
|
|
MinioExceptionHandler.handleException(e);
|
|
|
}
|
|
@@ -120,7 +126,8 @@ public class MinioStorageServiceImpl implements IFileStorageService {
|
|
|
// 确认桶是否存在
|
|
|
bucketName = ensureBucket(bucketName);
|
|
|
// 删除桶
|
|
|
- minioClient.removeBucket(bucketName);
|
|
|
+// minioClient.removeBucket(bucketName);
|
|
|
+ minioClient.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build());
|
|
|
} catch (Exception e) {
|
|
|
MinioExceptionHandler.handleException(e);
|
|
|
}
|
|
@@ -138,12 +145,14 @@ public class MinioStorageServiceImpl implements IFileStorageService {
|
|
|
bucketName = FileCommonConst.DEFAULT_BUCKET;
|
|
|
}
|
|
|
log.info("开始检查桶名:[{0}]是否存在", bucketName);
|
|
|
- boolean isExist = minioClient.bucketExists(bucketName);
|
|
|
+// boolean isExist = minioClient.bucketExists(bucketName);
|
|
|
+ boolean isExist = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
|
|
|
if(isExist) {
|
|
|
log.info("桶名:[{0}]已存在", bucketName);
|
|
|
return bucketName;
|
|
|
}
|
|
|
- minioClient.makeBucket(bucketName);
|
|
|
+// minioClient.makeBucket(bucketName);
|
|
|
+ minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
|
|
|
log.info("桶名:[{0}]不存在,创建成功", bucketName);
|
|
|
return bucketName;
|
|
|
}
|