From 1c15339269b83e859663e02b401c89b6e9e11b86 Mon Sep 17 00:00:00 2001 From: wangxianzhang Date: Wed, 14 Sep 2022 17:24:13 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90minio=E3=80=91=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=A4=96=E9=83=A8=E5=9F=9F=E5=90=8D?= =?UTF-8?q?=E5=92=8C=E5=86=85=E9=83=A8=E5=9F=9F=E5=90=8D=EF=BC=8C=E5=86=85?= =?UTF-8?q?=E9=83=A8=E5=9F=9F=E5=90=8D=E5=8F=AF=E4=BB=A5=E7=94=A8=E6=9D=A5?= =?UTF-8?q?=E5=86=85=E9=83=A8=E8=AE=BF=E9=97=AE=EF=BC=8C=E6=9B=B4=E5=BF=AB?= =?UTF-8?q?=EF=BC=8C=E6=9B=B4=E7=A8=B3=E5=AE=9A=EF=BC=9B=E5=A4=96=E9=83=A8?= =?UTF-8?q?=E5=9F=9F=E5=90=8D=E7=94=A8=E4=BA=8E=E7=BB=99=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E8=AE=BF=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/epmet/cloud/CloudStorageConfig.java | 10 ++++++++-- .../java/com/epmet/cloud/MinioStorageService.java | 11 ++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/cloud/CloudStorageConfig.java b/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/cloud/CloudStorageConfig.java index 384c77fa42..6b44c47d66 100644 --- a/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/cloud/CloudStorageConfig.java +++ b/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/cloud/CloudStorageConfig.java @@ -156,12 +156,18 @@ public class CloudStorageConfig implements Serializable { */ @Data public static class MinioStorageConfigProps { - private String minioDomain; + /** + * 外部访问域名,用于用户直接访问minio服务 + */ + private String minioExternalDomain; + /** + * 内部访问域名,用于服务集群内部使用 + */ + private String minioInternalDomain; private String minioEndPoint; private String minioAccessKey; private String minioSecretKey; private String minioPrefix; private String minioBucketName; } - } diff --git a/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/cloud/MinioStorageService.java b/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/cloud/MinioStorageService.java index 5d1cd1fad6..32bb5d51ee 100644 --- a/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/cloud/MinioStorageService.java +++ b/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/cloud/MinioStorageService.java @@ -28,15 +28,18 @@ public class MinioStorageService extends AbstractCloudStorageService { CloudStorageConfig.MinioStorageConfigProps props = config.getMinio().getConfigByPrivacy(null); + /** + * minio和服务在同一个局域网,则可以使用内网域名上传,速度更快更稳定 + */ minioClient = MinioClient.builder() - .endpoint(props.getMinioDomain()) // 保证和nginx的proxy_set_header Host 一致 + .endpoint(props.getMinioInternalDomain()) // 保证和nginx的proxy_set_header Host 一致 .credentials(props.getMinioAccessKey(), props.getMinioSecretKey()) .build(); } @Override public String getOssDomain(String privacy) { - return this.config.getMinio().getConfigByPrivacy(privacy).getMinioDomain(); + return this.config.getMinio().getConfigByPrivacy(privacy).getMinioExternalDomain(); } @Override @@ -74,7 +77,9 @@ public class MinioStorageService extends AbstractCloudStorageService { .build()); log.debug("minio上传文件成功。bucket:{}, object:{}, privacyType:{}", resp.bucket(), resp.object(), privacyType); - return props.getMinioDomain() + "/" + Paths.get(resp.bucket()).resolve(resp.object()).toString(); + + // 返回值要存储到数据库,供用户访问,因此使用外网域名 + return props.getMinioExternalDomain() + "/" + Paths.get(resp.bucket()).resolve(resp.object()).toString(); } catch (Exception e) { String errorMsg = ExceptionUtils.getErrorStackTrace(e); throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode(), errorMsg);