From 527abb7a9151133551562bd3465e376287643969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Tue, 30 Apr 2024 09:49:53 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20https=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20=E7=AB=99=E7=82=B9=E5=A1=AB=E5=9F=9F=E5=90=8D=20?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E5=90=AF=E7=94=A8=E8=B7=AF=E5=BE=84=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=E8=AE=BF=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/dromara/common/oss/core/OssClient.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/core/OssClient.java b/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/core/OssClient.java index e2a77031..5533297a 100644 --- a/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/core/OssClient.java +++ b/ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/core/OssClient.java @@ -34,7 +34,6 @@ import java.net.URI; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.time.Duration; /** @@ -84,6 +83,9 @@ public class OssClient { StaticCredentialsProvider credentialsProvider = StaticCredentialsProvider.create( AwsBasicCredentials.create(properties.getAccessKey(), properties.getSecretKey())); + //MinIO 使用 HTTPS 限制使用域名访问,站点填域名。需要启用路径样式访问 + boolean isStyle = !StringUtils.containsAny(properties.getEndpoint(), OssConstant.CLOUD_SERVICE); + //创建AWS基于 CRT 的 S3 客户端 this.client = S3AsyncClient.crtBuilder() .credentialsProvider(credentialsProvider) @@ -92,15 +94,15 @@ public class OssClient { .targetThroughputInGbps(20.0) .minimumPartSizeInBytes(10 * 1025 * 1024L) .checksumValidationEnabled(false) + .forcePathStyle(isStyle) .build(); //AWS基于 CRT 的 S3 AsyncClient 实例用作 S3 传输管理器的底层客户端 this.transferManager = S3TransferManager.builder().s3Client(this.client).build(); - // 检查是否连接到 MinIO,MinIO 使用 HTTPS 限制使用域名访问,需要启用路径样式访问 + // 创建 S3 配置对象 S3Configuration config = S3Configuration.builder().chunkedEncodingEnabled(false) - // minio 使用https限制使用域名访问 需要此配置 站点填域名 - .pathStyleAccessEnabled(!StringUtils.containsAny(properties.getEndpoint(), OssConstant.CLOUD_SERVICE)).build(); + .pathStyleAccessEnabled(isStyle).build(); // 创建 预签名 URL 的生成器 实例,用于生成 S3 预签名 URL this.presigner = S3Presigner.builder()