amazon-s3 - 如何使用aws cli更改对象的内容类型?

标签 amazon-s3 command-line-interface content-type aws-cli

我在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/

相关文章:

amazon-s3 - 如何将文件从 AWS EFS 复制到 AWS S3?

ruby-on-rails - delay_job和回形针-图像未处理,但没有错误?

Perl - 如何直接在 Perl shell/解释器中键入/执行/运行 Perl 语句?

javascript - 如何并行上传多个文件到亚马逊S3?

javascript - nodejs 中的两个 HTTP 请求问题

javascript - 在 Windows 10 机器上已经启动了一些其他 Node.js 文件后如何启动一个新的 Node.js 文件?

configuration - nginx - 是否有用于编辑配置文件的 CLI 工具?

android - 如何查找网址是否为音频/视频

angularjs - 如何阻止 Angular $http 反序列化响应主体?

javascript - 如何创建带有 Content-Type header 的响应?