create_object, or several other methods of the AmazonS3 class, the
$optsparameter often allows for both
headersis documented as "HTTP headers to send along with the request", it turns out that they are returned with the object (i.e. in the response) when that object is requested from S3. In contrast, keys in
metaare canonicalized, prepended with
x-amz-meta-, and returned that way.
That is, if you want to upload filenames like "$id-$md5.pdf" but deliver them to the user as "ContosoUserAgreement.pdf" in the Save-As dialog, then headers should contain a
Content-Dispositionkey with a value of
If you put it in meta instead, then the HTTP headers on retrieval will contain a
x-amz-meta-content-dispositionheader instead, which will not be honored by the browser.
I found all this out by uploading something like 12,000 files with the wrong metadata. I then wrote a script to fix it, which ran straight into the problem that
update_objectdoesn't work, so you have to use
copy_objectinstead. Note that when using
'metadataDirective' => 'REPLACE', you need to specify all the metadata you want, because it does what it says: it deletes all old metadata before adding the new metadata from the
copy_objectrequest, so that only the new metadata exists afterwards.