【问题标题】:SignatureDoesNotMatch error using restTemplate to get url request of S3SignatureDoesNotMatch 错误使用 restTemplate 获取 S3 的 url 请求
【发布时间】:2021-12-26 02:20:55
【问题描述】:

我正在尝试使用 restTemplate 发送 S3 的 HTTP GET 请求,但我收到 SignatureDoesNotMatch 错误:我们计算的请求签名与您提供的签名不匹配。检查您的密钥和签名方法。

有人知道什么会导致这个错误吗?

【问题讨论】:

  • 我曾经在使用预签名的 s3 url 时遇到过这样的问题。回到文档后,我发现我需要在两个不同的地方使用特定的参数。我使用的是 Boto3,我需要在 FieldsConditions 中设置 acl。仔细阅读文档很有可能会有很大帮助。
  • 请澄清您的具体问题或提供更多详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: http url get request spring-resttemplate


【解决方案1】:

找到问题了!

显然我的问题不准确,就像我从 S3 得到的错误一样 - 不是指示性的。

我真正在寻找的是如何使用 Rest Template 从 S3 url 下载文件。 所以只好添加如下配置,并用这段代码解决:

RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter());
HttpHeaders headers = new HttpHeaders();
String url = URLDecoder.decode(path, "UTF-8");
ResponseEntity<byte[]> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(headers), byte[].class);

【讨论】:

    猜你喜欢
    • 2015-04-29
    • 2020-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多