我在Amazon S3中存储了几个对象,我需要将其内容类型从text/html
更改为application/rss+xml
。我认为使用复制命令可以做到这一点,并为源和目标指定相同的路径。我正在尝试使用AWS cli工具执行此操作,但出现此错误:
$ aws s3 cp s3://mybucket/feed/ogg/index.html \
s3://mybucket/feed/ogg/index.html \
--content-type 'application/rss+xml'
copy failed: s3://mybucket/feed/ogg/index.html
to s3://mybucket/feed/ogg/index.html
A client error (InvalidRequest) occurred when calling the
CopyObject operation: This copy request is illegal because it is
trying to copy an object to itself without changing the object's
metadata, storage class, website redirect location or encryption
attributes.
如果我为源和目标指定了其他路径,则不会收到错误消息:
$ aws s3 cp s3://mybucket/feed/ogg/index.html \
s3://mybucket/feed/ogg/index2.html \
--content-type 'application/rss+xml'
copy: s3://mybucket/feed/ogg/index.html
to s3://mybucket/feed/ogg/index2.html
即使命令成功完成,也会使用
index2.html
内容类型而不是我指定的text/html
类型创建application/rss+xml
对象。如何修改此命令行以使其正常工作?
最佳答案
可以使用较低级别的s3api
进行此更改:
$ aws s3api copy-object --bucket archive --content-type "application/rss+xml" \
--copy-source archive/test/test.html --key test/test.html \
--metadata-directive "REPLACE"
http://docs.aws.amazon.com/cli/latest/reference/s3api/copy-object.html
问题只是无法指定
--metadata-directive
。感谢您指出open issue / feature request,纳尔斯特罗姆!
关于amazon-s3 - 如何使用aws cli更改对象的内容类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23548256/