From 502b692feed5f1441d17b34fc3e4b1d186702be1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=B0=8F=E7=8E=8B=E5=AD=90?= Date: Tue, 30 Apr 2024 15:36:52 +0800 Subject: [PATCH] =?UTF-8?q?OssClient=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/~$oyi-Flex-Guide.docx | Bin 0 -> 162 bytes .../java/com/ruoyi/common/oss/core/OssClient.java | 9 ++++++--- 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 doc/~$oyi-Flex-Guide.docx diff --git a/doc/~$oyi-Flex-Guide.docx b/doc/~$oyi-Flex-Guide.docx new file mode 100644 index 0000000000000000000000000000000000000000..fcd42e3fa9819ae3c2e99e74ae57ff52b9d59275 GIT binary patch literal 162 xcmd;eOv%m6%PcM_N-W7QVjvRmGB`4%Fyu01GUNeqF+&MM5kn%7%m>oc1^`8%3f%wz literal 0 HcmV?d00001 diff --git a/ruoyi-common/ruoyi-common-oss/src/main/java/com/ruoyi/common/oss/core/OssClient.java b/ruoyi-common/ruoyi-common-oss/src/main/java/com/ruoyi/common/oss/core/OssClient.java index aee7cfc..7be4c8e 100644 --- a/ruoyi-common/ruoyi-common-oss/src/main/java/com/ruoyi/common/oss/core/OssClient.java +++ b/ruoyi-common/ruoyi-common-oss/src/main/java/com/ruoyi/common/oss/core/OssClient.java @@ -83,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) @@ -91,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()