Search code examples
phpamazon-s3metadatacontent-type

How to set custom Metadata on Amazon PHP SDK


I tried:

$objS3->putObject(array(
    'Bucket'     => $sBucket
    'Key'        => $sBucketFolder . $sFilenameToSave,
    'SourceFile' => $sFile,
    'ACL'        => 'public-read'
    'Metadata'   => [
        'Content-Type'      => 'text/css',
        'Content-Encoding'  => 'gzip', 
    ]
));

But it did not work. Any idea?

Tks.


Solution

  • ContentType and ContentEncoding should not be sent as metadata. Use this instead:

    $objS3->putObject(array(
        'Bucket'          => $sBucket
        'Key'             => $sBucketFolder . $sFilenameToSave,
        'SourceFile'      => $sFile,
        'ACL'             => 'public-read',
        'ContentType'     => 'text/css',
        'ContentEncoding' => 'gzip'
    ));