1.问题描述
- 使用awssdk 2.x版本工具,通过s3协议上传文件到minIO服务上,如果endpoint使用IP地址,能够正常上传,若是使用域名,则会出现域名匹配不到的错误
2.解决办法
- 解决方法是从Github同样问题讨论模板中找到:github链接
- 因为awssdk 2.x会自动转成桶域名进行操作
(https://bucketName.endpoint)
,minio不存在桶域名概念,导致域名匹配不上,所以需要固定访问路径样式,不让其转变
S3Client.builder()
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("accessKey", "secretKey")))
.region(Region.AWS_GLOBAL)
.endpointOverride(URI.create("endpoint"))
.forcePathStyle(true)
.serviceConfiguration(S3Configuration.builder()
.chunkedEncodingEnabled(false)
.build())
.build();
S3Client.builder()
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("accessKey", "secretKey")))
.region(Region.AWS_GLOBAL)
.endpointOverride(URI.create("endpoint"))
.serviceConfiguration(S3Configuration.builder()
.pathStyleAccessEnabled(true)
.chunkedEncodingEnabled(false)
.build())
.build();