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