我怎样才能改变内容类型使用AWS CLI的对象? [英] How can I change the content-type of an object using aws cli?

查看:373
本文介绍了我怎样才能改变内容类型使用AWS CLI的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有存储在Amazon S3中的内容类型,我需要从的text / html 来改变多个对象应用程序/ RSS + XML 。我推测,它应该是可以用一个拷贝命令这样做,指定源和目的地相同的路径。我试图使用AWS CLI工具来做到这一点,但我得到这个错误:

I've got several objects stored in Amazon S3 whose content-type I need to change from text/html to application/rss+xml. I gather that it should be possible to do this with a copy command, specifying the same path for the source and destination. I'm trying to do this using the AWS cli tools, but I'm getting this error:

$ 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.

如果我指定一个不同的路径,源和目的,我没有得到错误:

If I specify a different path for source and destination, I don't get the error:

$ 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 内容类型创建,而不是应用程序/ RSS + XML 键入我指定的。

Even though the command completes successfully, the index2.html object is created with the text/html content type, not the application/rss+xml type that I specified.

我怎么能修改此命令行,使其工作?

How can I modify this command-line to make it work?

推荐答案

这是可能的使用水平低 s3api 来进行更改:

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 /最新/参考/ s3api /复制object.html

这个问题只是不能够指定 - 元数据的指令。感谢您指出href="https://github.com/aws/aws-cli/issues/652" rel="nofollow">悬而未决的问题/功能要求,nelstrom的

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

这篇关于我怎样才能改变内容类型使用AWS CLI的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆