From aa3cde8f590bd9e739a484eece82ec8d8c4917bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=BF=8A?= <873019219@qq.com> Date: Sun, 19 Sep 2021 11:30:05 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20minio=20=E5=92=8C=20s3=20=E5=AD=98?= =?UTF-8?q?=E5=82=A8=E5=BC=95=E6=93=8E=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=20region=20=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/im/zhaojun/zfile/service/impl/MinIOServiceImpl.java | 5 ++++- .../java/im/zhaojun/zfile/service/impl/S3ServiceImpl.java | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/im/zhaojun/zfile/service/impl/MinIOServiceImpl.java b/src/main/java/im/zhaojun/zfile/service/impl/MinIOServiceImpl.java index 4168ccc..556215b 100644 --- a/src/main/java/im/zhaojun/zfile/service/impl/MinIOServiceImpl.java +++ b/src/main/java/im/zhaojun/zfile/service/impl/MinIOServiceImpl.java @@ -39,6 +39,8 @@ public class MinIOServiceImpl extends AbstractS3BaseFileService implements BaseF String accessKey = stringStorageConfigMap.get(StorageConfigConstant.ACCESS_KEY).getValue(); String secretKey = stringStorageConfigMap.get(StorageConfigConstant.SECRET_KEY).getValue(); String endPoint = stringStorageConfigMap.get(StorageConfigConstant.ENDPOINT_KEY).getValue(); + String region = stringStorageConfigMap.get(StorageConfigConstant.REGION_KEY).getValue(); + bucketName = stringStorageConfigMap.get(StorageConfigConstant.BUCKET_NAME_KEY).getValue(); basePath = stringStorageConfigMap.get(StorageConfigConstant.BASE_PATH).getValue(); isPrivate = Convert.toBool(stringStorageConfigMap.get(StorageConfigConstant.IS_PRIVATE).getValue(), true); @@ -51,7 +53,7 @@ public class MinIOServiceImpl extends AbstractS3BaseFileService implements BaseF s3Client = AmazonS3ClientBuilder.standard() .withPathStyleAccessEnabled(true) .withCredentials(new AWSStaticCredentialsProvider(credentials)) - .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, "minio")).build(); + .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, region)).build(); testConnection(); isInitialized = true; @@ -72,6 +74,7 @@ public class MinIOServiceImpl extends AbstractS3BaseFileService implements BaseF add(new StorageConfig("secretKey", "SecretKey")); add(new StorageConfig("endPoint", "服务地址")); add(new StorageConfig("bucketName", "存储空间名称")); + add(new StorageConfig("region", "地域")); add(new StorageConfig("basePath", "基路径")); add(new StorageConfig("isPrivate", "是否是私有空间")); }}; diff --git a/src/main/java/im/zhaojun/zfile/service/impl/S3ServiceImpl.java b/src/main/java/im/zhaojun/zfile/service/impl/S3ServiceImpl.java index 60e6ccd..1c30bdb 100644 --- a/src/main/java/im/zhaojun/zfile/service/impl/S3ServiceImpl.java +++ b/src/main/java/im/zhaojun/zfile/service/impl/S3ServiceImpl.java @@ -40,6 +40,7 @@ public class S3ServiceImpl extends AbstractS3BaseFileService implements BaseFile String accessKey = stringStorageConfigMap.get(StorageConfigConstant.ACCESS_KEY).getValue(); String secretKey = stringStorageConfigMap.get(StorageConfigConstant.SECRET_KEY).getValue(); String endPoint = stringStorageConfigMap.get(StorageConfigConstant.ENDPOINT_KEY).getValue(); + String region = stringStorageConfigMap.get(StorageConfigConstant.REGION_KEY).getValue(); super.domain = stringStorageConfigMap.get(StorageConfigConstant.DOMAIN_KEY).getValue(); super.basePath = stringStorageConfigMap.get(StorageConfigConstant.BASE_PATH).getValue(); @@ -54,8 +55,7 @@ public class S3ServiceImpl extends AbstractS3BaseFileService implements BaseFile log.debug("初始化存储策略 [{}] 失败: 参数不完整", getStorageTypeEnum().getDescription()); isInitialized = false; } else { - String region = ""; - if (StringUtils.isNotNullOrEmpty(endPoint)) { + if (StrUtil.isNotEmpty(endPoint) && StrUtil.isEmpty(region)) { region = endPoint.split("\\.")[1]; } BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); @@ -81,6 +81,7 @@ public class S3ServiceImpl extends AbstractS3BaseFileService implements BaseFile add(new StorageConfig("secretKey", "SecretKey")); add(new StorageConfig("endPoint", "服务地址(EndPoint)")); add(new StorageConfig("bucketName", "存储空间名称")); + add(new StorageConfig("region", "地域")); add(new StorageConfig("basePath", "基路径")); add(new StorageConfig("domain", "加速域名")); add(new StorageConfig("pathStyle", "域名风格"));