Commit 35b6f9d31c9052af7e1bc783eddaf35bb50a9f53

Authored by YunaiV
1 parent 94ee7d65

feat:【infra】s3 增加 region 配置

yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/framework/file/core/client/s3/S3FileClient.java
... ... @@ -173,13 +173,13 @@ public class S3FileClient extends AbstractFileClient<S3FileClientConfig> {
173 173 return config.getRegion();
174 174 }
175 175  
176   - // 2. 尝试从 endpoint 中解析 region
  176 + // 2.1 尝试从 endpoint 中解析 region
177 177 String endpoint = config.getEndpoint();
178 178 if (StrUtil.isEmpty(endpoint)) {
179 179 return "us-east-1";
180 180 }
181 181  
182   - // 移除协议头(http:// 或 https://)
  182 + // 2.2 移除协议头(http:// 或 https://)
183 183 String host = endpoint;
184 184 if (HttpUtil.isHttp(endpoint) || HttpUtil.isHttps(endpoint)) {
185 185 try {
... ... @@ -189,12 +189,11 @@ public class S3FileClient extends AbstractFileClient<S3FileClientConfig> {
189 189 return "us-east-1";
190 190 }
191 191 }
192   -
193 192 if (StrUtil.isEmpty(host)) {
194 193 return "us-east-1";
195 194 }
196 195  
197   - // 3. AWS S3 格式:s3.us-west-2.amazonaws.com 或 s3.amazonaws.com
  196 + // 3.1 AWS S3 格式:s3.us-west-2.amazonaws.com 或 s3.amazonaws.com
198 197 if (host.contains("amazonaws.com")) {
199 198 // 匹配 s3.{region}.amazonaws.com 格式
200 199 if (host.startsWith("s3.") && host.contains(".amazonaws.com")) {
... ... @@ -206,8 +205,7 @@ public class S3FileClient extends AbstractFileClient<S3FileClientConfig> {
206 205 // s3.amazonaws.com 或 s3-accelerate.amazonaws.com 使用默认值
207 206 return "us-east-1";
208 207 }
209   -
210   - // 4. 阿里云 OSS 格式:oss-cn-beijing.aliyuncs.com
  208 + // 3.2 阿里云 OSS 格式:oss-cn-beijing.aliyuncs.com
211 209 if (host.contains(S3FileClientConfig.ENDPOINT_ALIYUN)) {
212 210 // 匹配 oss-{region}.aliyuncs.com 格式
213 211 if (host.startsWith("oss-") && host.contains("." + S3FileClientConfig.ENDPOINT_ALIYUN)) {
... ... @@ -217,8 +215,7 @@ public class S3FileClient extends AbstractFileClient<S3FileClientConfig> {
217 215 }
218 216 }
219 217 }
220   -
221   - // 5. 腾讯云 COS 格式:cos.ap-shanghai.myqcloud.com
  218 + // 3.3 腾讯云 COS 格式:cos.ap-shanghai.myqcloud.com
222 219 if (host.contains(S3FileClientConfig.ENDPOINT_TENCENT)) {
223 220 // 匹配 cos.{region}.myqcloud.com 格式
224 221 if (host.startsWith("cos.") && host.contains("." + S3FileClientConfig.ENDPOINT_TENCENT)) {
... ... @@ -229,7 +226,7 @@ public class S3FileClient extends AbstractFileClient<S3FileClientConfig> {
229 226 }
230 227 }
231 228  
232   - // 6. 其他情况(MinIO、七牛云等)使用默认值
  229 + // 3.4 其他情况(MinIO、七牛云等)使用默认值
233 230 return "us-east-1";
234 231 }
235 232  
... ...
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/framework/file/core/client/s3/S3FileClientConfig.java
... ... @@ -83,7 +83,7 @@ public class S3FileClientConfig implements FileClientConfig {
83 83 private Boolean enablePublicAccess;
84 84  
85 85 /**
86   - * AWS 区域
  86 + * 区域
87 87 * 1. AWS S3:https://docs.aws.amazon.com/general/latest/gr/s3.html 例如说,us-east-1、us-west-2
88 88 * 2. MinIO:可以填任意值,通常使用 us-east-1
89 89 * 3. 阿里云:不需要填写,会自动识别
... ...