简体   繁体   English

如何使用预签名的 URL 以及 s3 aws-sdk-ruby v3 中的标签上传 object

[英]How to upload an object using presigned URL along with tags in s3 aws-sdk-ruby v3

I am trying to upload an object using a presigned URL. But I want to upload the the object along with tags.我正在尝试使用预签名的 URL 上传 object。但我想上传 object 和标签。 What is the proper way to do it?正确的做法是什么?

Approach 1:方法一:

I tried the following ruby code:我尝试了以下 ruby 代码:

signer = Aws::S3::Presigner.new
signer.presigned_url(:put_object, bucket: bucket_name, key: url, tagging: 'taggingName=tagValue')

But this is only uploading the object, but not adding tags.但这只是上传object,并没有添加标签。

Approach 2:方法二:

I tried to whitelist 'x-amz-tagging' header and tried to upload the file along with the header from client side.我尝试将“x-amz-tagging”header 列入白名单,并尝试从客户端上传文件和 header。

Ruby code: Ruby 代码:

signer = Aws::S3::Presigner.new
url = signer.presigned_url(:put_object, bucket: bucket_name, key: public_url, whitelist_headers: ['x-amz-tagging'])

Client Side code:客户端代码:

return $http({
      method: 'PUT',
      url: presigned_url,
      ignoreLoadingBar: true,
      data: file,
      headers: {
        'Content-Type': file.type,
        'x-amz-tagging': 'taggingName=tagValue'
      }
    })

But this is throwing me an error while uploading saying "x-amz-tagging" is not signed.但这在上传时给我一个错误,说“x-amz-tagging”未签名。

Am using aws-sdk-ruby v3 (Ror)我正在使用 aws-sdk-ruby v3 (Ror)

As per the documentation根据文档

The tag-set for the object. The tag-set must be encoded as URL Query parameters. object 的标记集。标记集必须编码为 URL 查询参数。 (For example, "Key1=Value1") (例如,“Key1=Value1”)

And the error is seems to be saying the same thing错误似乎是在说同样的话

"x-amz-tagging" is not signed. “x-amz-tagging”未签名。

So when you create the URL you need to provide what kind of tags with corresponding values.所以当你创建URL时你需要提供什么样的标签和相应的值。

    PUT /example-object HTTP/1.1
    Host: example-bucket.s3.<Region>.amazonaws.com   
    Accept: */*   
    Authorization:authorization string   
    Date: Thu, 22 Sep 2016 21:58:13 GMT   
    x-amz-tagging: tag1=value1&tag2=value2

    [... bytes of object data]   
     

Example 6th on the same documentation page.同一文档页面上的示例 6。

Whatever tags you have provided while creating the signed url, you extract the same from url and pass them to x-amz-tagging无论您在创建签名的 url 时提供了什么标签,您都可以从 url 中提取相同的标签并将它们传递给x-amz-tagging

something like就像是

     const tag = signS3URL.tag;
     ...
     const options = {
        url: signedUrl,
        path: fileUrl,
        method: "PUT",
        headers: { "Content-Type": file.mimeType, "X-Amz-Tagging": tag }
    };
  

I am not too good with JS though.不过我不太擅长 JS。

Last but not least check your cloudtrail logs for errors for tagging the object.最后但并非最不重要的一点是,检查您的 cloudtrail 日志中是否存在标记 object 的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 golang aws sdk v2 获取未预签名的 s3 object url 的简单示例 - Simple Example of how to get the un-presigned s3 object url using the golang aws sdk v2 使用预签名 URL“SignatureDoesNotMatch”获取 AWS S3 Object - Fetching AWS S3 Object using Presigned URL "SignatureDoesNotMatch" 用于 nodejs 的 AWS SDK v3,如何获取 s3 存储桶的标签? - AWS SDK v3 for nodejs, how to get tags of an s3 bucket? 使用 nodejs SDK v3 将 stream 上传到 Amazon s3 - Upload stream to Amazon s3 using nodejs SDK v3 AWS S3 Go Sdk - 添加 ACL 时预签名 url 无法上传文件 - AWS S3 Go Sdk - Presigned url unable upload file when add ACL AWS Java SDK 2.0 S3 预签名 URL 公共 object 访问 - AWS Java SDK 2.0 S3 presigned URL public object access 将带有预签名 url 的分段上传从 aws javascript sdk v2 迁移到 v3 - migrate multipart upload with presigned urls from aws javascript sdk v2 to v3 AWS S3 预签名 url 上传返回 200 但文件不在使用 NodeJS 和节点获取的存储桶中 - AWS S3 presigned url upload returns 200 but the file is not in the bucket using NodeJS & node-fetch S3 为使用 aws-sdk v3 预签名的 PutObject 命令 url 提供 SignatureDoesNotMatch 错误 - S3 gives SignatureDoesNotMatch error for PutObject command pre-signed url using aws-sdk v3 如何使用 aws-sdk-2.x 从 S3 存储桶中获取 object 的 S3 URL - How to get S3 URL for the object from S3 bucket using aws-sdk-2.x
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM