[英]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.