带有其他用户参数的AWS S3预签名URL到PUT对象 [英] AWS S3 Presigned URL to PUT object with additional user params not working

查看:232
本文介绍了带有其他用户参数的AWS S3预签名URL到PUT对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试生成一个预签名的url,以将文件与其他一些元数据一起放入s3

I am trying to generate a presigned url to put files into s3 with some additional metadata with it

GeneratePresignedUrlRequest generatePresignedUrlRequest =
    new GeneratePresignedUrlRequest(bucket, objectKey)
        .withMethod(httpMethod)
        .withExpiration(expiration);
if (params != null) {
  params.forEach(
      (k, v) ->
          generatePresignedUrlRequest.addRequestParameter(
              Headers.S3_USER_METADATA_PREFIX + k.toLowerCase(), v));
}

其中params是Map<String, String>

但是在上载文件后,当我尝试使用

but after uploading file when I try to get the object using

AmazonS3.getObjectMetadata(bucketName, key).getUserMetadata()

返回一个空的地图.

也尝试了generatePresignedUrlRequest.putCustomRequestHeader(key, value) 但是我看到在生成的url字符串中没有发送标头值.

Also tried generatePresignedUrlRequest.putCustomRequestHeader(key, value) But I see that in the generated url string the header values are not being sent.

注意:我正在将Amazons3.generatePresignedUrl(generatePresignedUrlRequest).toString();发送到UI

Note : I am sending Amazons3.generatePresignedUrl(generatePresignedUrlRequest).toString(); to UI

任何帮助将不胜感激. 附加说明:我正在尝试在不是HTTPS的本地嘲笑S3服务器中执行此操作

Any help will be appreciated. Additional Note : I am trying to do this in my local mockS3 server which is not HTTPS

推荐答案

我认为您在混淆请求参数和请求标头.

I think you're confusing request parameters and request headers.

addRequestParameter请求参数添加到已签名的URL.

addRequestParameter adds request parameters to the signed URL.

S3的PUT操作希望请求标头添加元数据( https://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html )

While S3's PUT operation expects request headers to add meta data (https://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html)

您需要改用putCustomRequestHeader.

请注意,除了使用这些参数签名外,客户端还 实际发送的请求将必须传递与实际相同的值 标头.换句话说,URL生成器代码和客户端代码都需要 知道正在发送的标头.

Note that in addition to signing with these parameters, the client that actually sends the request will have to pass the same values as actual headers. In other words both the URL generator code and client code need to know the headers being sent.

这篇关于带有其他用户参数的AWS S3预签名URL到PUT对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆