opt,上传s3逻辑优化

This commit is contained in:
luke 2025-06-21 00:48:57 +08:00
parent e174c085f0
commit 0062ebdbac

View File

@ -20,6 +20,8 @@ public class MinioOSGatewayImpl implements ObjectStorageGateway {
private final MinioClient minioClient;
private final MinioClient localMinioClient;
private final ObjectStorageProperties objectStorageProperties;
@ -33,6 +35,11 @@ public class MinioOSGatewayImpl implements ObjectStorageGateway {
.endpoint(endpoint)
.credentials(accessKey, secretKey)
.build();
// 为了提升上传的速度创建本地 minio 客户端
this.localMinioClient = MinioClient.builder()
.endpoint("http://localhost:19000")
.credentials(accessKey, secretKey)
.build();
this.objectStorageProperties = objectStorageProperties;
}
@ -49,7 +56,7 @@ public class MinioOSGatewayImpl implements ObjectStorageGateway {
@Override
public void uploadFile(String bucket, String objectPath, MultipartFile file) throws Exception {
minioClient.putObject(PutObjectArgs.builder()
localMinioClient.putObject(PutObjectArgs.builder()
.bucket(bucket)
.object(objectPath)
.stream(file.getInputStream(), file.getSize(), -1)
@ -64,7 +71,7 @@ public class MinioOSGatewayImpl implements ObjectStorageGateway {
boolean isPublic = isPublicBucket(bucket);
if (isPublic) {
// 直接拼接公网 URL你自己的 CDN 域名
// 直接拼接公网 URL
return String.format("http://s3.wisdompulse.cn/%s/%s", bucket, objectPath);
} else {
// 生成预签名链接最大 7