How can I change the content-type of an object using aws cli?

岁酱吖の 提交于 2019-12-01 03:17:55

It's possible to use the low level s3api to make this change:

$ 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

The problem was just not being able to specify the --metadata-directive. Thanks for pointing out the open issue / feature request, nelstrom!

You can also do it with the higher level API, by copying a file over itself but marking it as a change in metadata:

aws s3 cp \
  --content-type "application/rss+xml" \
  --metadata-directive REPLACE \
  s3://mybucket/myfile \
  s3://mybucket/myfile 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!