From bb793d71e7bb47e8a036dba4d07b132cecc24c81 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: Fri, 18 Feb 2022 14:05:32 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20minio=20=E9=80=82?= =?UTF-8?q?=E9=85=8D=20https=20=E5=AF=BC=E8=87=B4=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/oss/service/impl/MinioOssStrategy.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/MinioOssStrategy.java b/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/MinioOssStrategy.java index eb2e7704..93f88fb3 100644 --- a/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/MinioOssStrategy.java +++ b/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/MinioOssStrategy.java @@ -9,6 +9,8 @@ import com.ruoyi.oss.exception.OssException; import com.ruoyi.oss.properties.OssProperties; import com.ruoyi.oss.service.abstractd.AbstractOssStrategy; import io.minio.*; +import io.minio.http.HttpUtils; +import okhttp3.HttpUrl; import org.springframework.http.MediaType; import org.springframework.stereotype.Component; @@ -29,10 +31,15 @@ public class MinioOssStrategy extends AbstractOssStrategy { public void init(OssProperties ossProperties) { super.init(ossProperties); try { - minioClient = MinioClient.builder() - .endpoint(properties.getEndpoint(), 443, OssConstant.IS_HTTPS.equals(ossProperties.getIsHttps())) - .credentials(properties.getAccessKey(), properties.getSecretKey()) - .build(); + MinioClient.Builder builder = MinioClient.builder(); + if (OssConstant.IS_HTTPS.equals(ossProperties.getIsHttps())) { + HttpUrl url = HttpUtils.getBaseUrl(properties.getEndpoint()) + .newBuilder().scheme("https").build(); + builder.endpoint(url); + } else { + builder.endpoint(properties.getEndpoint()); + } + minioClient = builder.credentials(properties.getAccessKey(), properties.getSecretKey()).build(); createBucket(); } catch (Exception e) { throw new OssException("Minio存储配置错误! 请检查系统配置:[" + e.getMessage() + "]");