我有一个用于将文件上传到 aws s3 的 Node 程序,我需要在请求 header 中指定 x-amz-tagging。我尝试了一些方法,但它不起作用!
function buildRequestHeader() {
return {
'Content-Length': fileBuffer.size,
'Content-Type': mimeType,
'x-amz-acl': 'public-read',
'x-amz-tagging' :{"tag1":'abcd',"tag2":'efgh'}
}
}
我从 aws 文档中看到了一些东西,
PUT object-key?tagging HTTP/1.1
Host: examplebucket.s3.amazonaws.com
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>
您能解释一下它是如何工作的吗?
最佳答案
您显示的代码片段来自两种不同的标记方法,第一种在 object creation 期间, 第二个是 adding tags to an existing object .
x-amz-tagging
header 是您在对象创建期间使用的 header ,但它使用 different syntax比你的例子。试试这个:
function buildRequestHeader() {
return {
'Content-Length': fileBuffer.size,
'Content-Type': mimeType,
'x-amz-acl': 'public-read',
'x-amz-tagging': 'tag1=abcd&tag2=efgh'
}
}
关于javascript - 使用 x-amz-tagging 请求 header 指定标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42968480/