opt,上传s3逻辑优化
This commit is contained in:
parent
e174c085f0
commit
0062ebdbac
@ -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 天)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user