admin管理员组文章数量:1313121
I have a Node program for file uploading to aws s3, I need to specify the x-amz-tagging with the request header. I tried something but it doesn't work!
function buildRequestHeader() {
return {
'Content-Length': fileBuffer.size,
'Content-Type': mimeType,
'x-amz-acl': 'public-read',
'x-amz-tagging' :{"tag1":'abcd',"tag2":'efgh'}
}
}
I have a Node program for file uploading to aws s3, I need to specify the x-amz-tagging with the request header. I tried something but it doesn't work!
function buildRequestHeader() {
return {
'Content-Length': fileBuffer.size,
'Content-Type': mimeType,
'x-amz-acl': 'public-read',
'x-amz-tagging' :{"tag1":'abcd',"tag2":'efgh'}
}
}
I have seen something from aws docs,
PUT object-key?tagging HTTP/1.1
Host: examplebucket.s3.amazonaws.
Content-Length: length
Content-MD5: pUNXr/BjKK5G2UKExample==
x-amz-date: 20160923T001956Z
Authorization: authorization string
<Tagging>
<TagSet>
<Tag>
<Key>tag1</Key>
<Value>val1</Value>
</Tag>
<Tag>
<Key>tag2</Key>
<Value>val2</Value>
</Tag>
</TagSet>
</Tagging>
Could you please explain how it works?
Share Improve this question asked Mar 23, 2017 at 6:11 SabreenaSabreena 6492 gold badges13 silver badges25 bronze badges2 Answers
Reset to default 6The code snippets you show are from two different methods of tagging, the first during object creation, the second is adding tags to an existing object.
The x-amz-tagging
header is what you would use during object creation, but it uses a different syntax than in your example. Try this instead:
function buildRequestHeader() {
return {
'Content-Length': fileBuffer.size,
'Content-Type': mimeType,
'x-amz-acl': 'public-read',
'x-amz-tagging': 'tag1=abcd&tag2=efgh'
}
}
const fs= require('fs');
const AWS = require('aws-sdk');
const s3 = new AWS.S3({'accesskey':'accesskeyvalue','region':'your s3 region'})
s3.upload(
{
Bucket: bucket_name,
Key: key,
Tagging: 'tag1=abcd&tag2=efgh',
Body: fs.createReadStream('./filename.filetype'),
}
this method is also working!!
本文标签: javascriptSpecify tags using the xamztagging request headerStack Overflow
版权声明:本文标题:javascript - Specify tags using the x-amz-tagging request header - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741936389a2405880.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论