12

In S3 REST API I am adding metadata to an existing object by using the PUT (Copy) command and copying a key to the same location with 'x-amz-metadata-directive' = 'REPLACE'

What I want to do is change the download file name by setting:

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

This sets the metadata correctly but when I download the file it still uses the key name instead of 'foo.bar'

I use a software tool S3 Browser to view the metadata and it looks correct (apart from 'Content-Disposition' being all lower case as that's was S3 ask me to sign)

Then using S3 Browser I just pressed, then save without changing anything and now it works???

What am I missing how come setting a metadata 'Content-Disposition: attachment; filename=foo.bar;' from my web app does not work but does work from S3 Browser?

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Daveo
  • 19,018
  • 10
  • 48
  • 71
  • Shouldn't this question actually be titled something like "Change Content-Disposition of existing S3 object", since that is the actual problem it is trying to solve? – natevw Jan 21 '11 at 01:09
  • yeah probably makes more sense, I have changed the title now. However Content-Disposition and metadata are treated the same way – Daveo Jan 22 '11 at 06:44

2 Answers2

8

Edited for clarity:

Content-Disposition must be set explicitly and not included as x-amz-meta-Content-Disposition. All metadata header names must start with "x-amz-meta-" and be all lowercase.

Thanks to @Eyal for clarifying.

Original:

>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.
Sammy Taylor
  • 298
  • 1
  • 12
Daveo
  • 19,018
  • 10
  • 48
  • 71
  • 14
    In your round-about way, you're saying that all metadata header names must start with "x-amz-meta-" and be all lowercase. You could've just say it instead of asking us to "notice". – Eyal Sep 19 '12 at 22:44
3

here: this uses the cli to set the content-disposition header on all files in a path inside a bucket (and also sets them as public):

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
FuzzyAmi
  • 7,543
  • 6
  • 45
  • 79