MinIO异常the region is wrong; expecting ‘us-east-1‘

io.minio.errors.ErrorResponseException: The authorization header is malformed; the region is wrong; expecting ‘us-east-1’

1. 现象

在使用MINIO上传文件到MinServer时候,后端java报错
io.minio.errors.ErrorResponseException: The authorization header is malformed; the region is wrong; expecting 'us-east-1'


2. 环境

  1. minio-3.0.10
<dependency>
    <groupId>io.minio</groupId>
    <artifactId>minio</artifactId>
    <version>3.0.10</version>
</dependency>
  1. linux

3. 解决

将 minio升级到5.0.4

<dependency>
    <groupId>io.minio</groupId>
    <artifactId>minio</artifactId>
    <version>5.0.4</version>
</dependency>

4. 解决历程

4.1 完整errorlog

首先自己调用MINIO的putObject方法,minioClient.putObject(minIOUtil.getBucketName(), zipFileName, inputStream, "application/json");比较完整err如下:

[qtp852143641-27] com.wx.x.x.x.RestfulCatchAOP 83 apply - operation failed(操作失败)s io.minio.errors.ErrorResponseException: The authorization header is malformed; the region is wrong; expecting 'us-east-1'.
	at io.minio.MinioClient.execute(MinioClient.java:1201) ~[minio-3.0.10.jar:3.0.10]
	at io.minio.MinioClient.executeGet(MinioClient.java:1294) ~[minio-3.0.10.jar:3.0.10]
	at io.minio.MinioClient.listIncompleteUploads(MinioClient.java:4294) ~[minio-3.0.10.jar:3.0.10]
	at io.minio.MinioClient.access$300(MinioClient.java:158) ~[minio-3.0.10.jar:3.0.10]
	at io.minio.MinioClient$7$1.populate(MinioClient.java:4159) ~[minio-3.0.10.jar:3.0.10]
	at io.minio.MinioClient$7$1.hasNext(MinioClient.java:4194) ~[minio-3.0.10.jar:3.0.10]
	at io.minio.MinioClient.getLatestIncompleteUploadId(MinioClient.java:4062) ~[minio-3.0.10.jar:3.0.10]
	at io.minio.MinioClient.putObject(MinioClient.java:3740) ~[minio-3.0.10.jar:3.0.10]
	at io.minio.MinioClient.putObject(MinioClient.java:3383) ~[minio-3.0.10.jar:3.0.10]
	at com.x.x.x.TdpServiceImpl.downLoad(TdpServiceImpl.java:142) ~[linkis-metadata-0.9.3.jar:?]
4.2 阅读errorLog
自己的TdpServiceImpl.java:142行 minioClient.putObject(minIOUtil.getBucketName(), zipFileName, inputStream, "application/json")
↓
MinioClient.java:3383  putObject(bucketName, objectName, null, new BufferedInputStream(stream), headerMap);
↓
MinioClient.java:3740 检查是否存在不完整的分段上传 String uploadId = getLatestIncompleteUploadId(bucketName, objectName);
↓
MinioClient.java:4062 返回给定存储桶名称和对象名称的不完整分段上传的最新上传ID。for (Result<Upload> result : listIncompleteUploads(bucketName, objectName, true, false)) {
↓
MinioClient.java:4194 填充populate();
↓
MinioClient.java:4159  this.listMultipartUploadsResult = listIncompleteUploads(bucketName, nextKeyMarker, nextUploadIdMarker,
                                                                      prefix, delimiter, 1000);
↓
MinioClient.java:158 初始化 public class MinioClient {
↓
MinioClient.java:4294 HttpResponse response = executeGet(bucketName, null, null, queryParamMap);
↓
MinioClient.java:1294 return execute(Method.GET, getRegion(bucketName), bucketName, objectName, headerMap, queryParamMap, null, 0);
↓
MinioClient.java:1201 throw new ErrorResponseException(errorResponse, response);

整体看下来,感觉contentType设置的不对,跟踪源码,发现contentType如果null,系统会自动设置一个。

于是minioClient.putObject(minIOUtil.getBucketName(), zipFileName, inputStream, null)运行后还是同样的错误the region is wrong; expecting 'us-east-1'.

4.3 谷歌

于是整体谷歌 io.minio.errors.ErrorResponseException: The authorization header is malformed; the region is wrong; expecting ‘us-east-1’

找到 https://github.com/minio/minio-java/issues/732 发现缺失是minIO的bug,然后已近修复 https://github.com/minio/minio-java/commit/22c7b122f770cbf4a2cb7d4b491e7d63fa6b5a94
在这里插入图片描述
在版本大于5.0.4以上就修复。
在这里插入图片描述
修复后源码如下


 private static final String US_EAST_1 = "us-east-1";
 
  public void makeBucket(String bucketName, String region)
    throws InvalidBucketNameException, RegionConflictException, NoSuchAlgorithmException, InsufficientDataException,
                IOException, InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
                InternalException {
    // If region param is not provided, set it with the one provided by constructor
    if (region == null) {
      region = this.region;
    }
    // If constructor already sets a region, check if it is equal to region param if provided
    if (this.region != null && !this.region.equals(region)) {
      throw new RegionConflictException("passed region conflicts with the one previously specified");
    }
    String configString;
    if (region == null || US_EAST_1.equals(region)) {
      // for 'us-east-1', location constraint is not required.  for more info
      // http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
      configString = "";
    } else {
      CreateBucketConfiguration config = new CreateBucketConfiguration(region);
      configString = config.toString();
    }

    HttpResponse response = executePut(bucketName, null, null, null, US_EAST_1, configString, 0);
    response.body().close();
  }

升级后果然问题没有再出现;

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

water___Wang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值