【问题标题】:Change Content-Disposition of existing S3 object更改现有 S3 对象的 Content-Disposition
【发布时间】:2021-06-10 12:53:45
【问题描述】:

在 S3 REST API 中,我使用 PUT(复制)命令将元数据添加到现有对象,并使用 'x-amz-metadata-directive' = 'REPLACE' 将密钥复制到同一位置

我要做的是通过设置更改下载文件名:

Content-Disposition: attachment; filename=foo.bar;

这会正确设置元数据,但是当我下载文件时,它仍然使用键名而不是 'foo.bar'

我使用软件工具 S3 Browser 查看元数据,看起来正确(除了 'Content-Disposition' 全部小写,因为那是 S3 要求我签名)

然后使用我刚刚按下的S3浏览器,然后保存而不更改任何内容,现在它可以工作了???

我错过了什么,为什么从我的网络应用程序设置元数据 'Content-Disposition: attachment; filename=foo.bar;' 不起作用,但在 S3 浏览器中起作用?

【问题讨论】:

  • 不应该把这个问题命名为“更改现有 S3 对象的内容处置”之类的东西,因为这是它试图解决的实际问题吗?
  • 是的可能更有意义,我现在更改了标题。但是 Content-Disposition 和元数据的处理方式相同

标签: amazon-web-services amazon-s3 metadata


【解决方案1】:

为清楚起见进行了编辑:

Content-Disposition 必须明确设置,并且不包含在 x-amz-meta-Content-Disposition 中。所有元数据标头名称必须以“x-amz-meta-”开头并且全部小写。

感谢@Eyal 的澄清。

原文:

>SOLVED:
>
>The Doco at http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?RESTAuthentication.html
>
>seems to be wrong it says:
>
>Notice how the 'x-amz-' headers are sorted, white-space trimmed, converted tolowercase, and multiple headers with the same name have been joined using a comma toseparate values.
>
>Note how only the Content-Type and Content-MD5HTTPentity headers appear in the StringToSign .The otherContent-* entity headers do not.
However Content-Disposition must be set specifically and not included as : x-amz-meta-Content-Disposition
>
>It now works fine.

【讨论】:

  • 在您的迂回方式中,您是说所有元数据标头名称必须以“x-amz-meta-”开头并且全部小写。您可以直接说出来,而不是要求我们“注意”。
【解决方案2】:

这里:这使用 cli 为存储桶内路径中的所有文件设置 content-disposition 标头(并将它们设置为公共):

aws s3 ls s3://mybucket/brand_img/ios/|awk {'print $4'} > objects.txt

 while read line; do aws s3api copy-object --bucket mybucket  \
--copy-source /mybucket/brand_img/ios/$line --key brand_img/ios/$line \
--metadata-directive REPLACE --metadata Content-Disposition=$line --acl public-read; done < objects.txt

【讨论】:

  • 这是否会产生 aws 复制文件成本,因为我有 100 个 20gb 大小的文件,我想更改其内容配置
猜你喜欢
  • 2012-06-23
  • 1970-01-01
  • 2010-11-28
  • 2021-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-11
相关资源
最近更新 更多