How to set Content-Disposition Headers as a default on Amazon S3 Bucket How to set Content-Disposition Headers as a default on Amazon S3 Bucket wordpress wordpress

How to set Content-Disposition Headers as a default on Amazon S3 Bucket


Unfortunately there is no way to set this for an entire bucket in S3, and also Cloudfront can only set Cache-Headers

But you can set The Content-disposition parameter when uploading files to S3.

For existing files, you must change the Header, so loop through every object in the Bucket, and copy it to itself using the new headers.

All I can say now, please post the code that uploads the file to S3.


First, you need to locate the code that puts the object in the bucket.You can use notepad++ to search for "putObject" within the php files of whatever plugin you are using.An example code from another WP plugin that stores files to S3 is as follows:

$this->s3->putObject( array(            'Bucket'     => $bucket,            'Key'        => $file['name'],            'SourceFile' => $file['file'],        ) );

Now, simply add ContentDisposition' => 'attachment' like so:

$this->s3->putObject( array(            'Bucket'     => $bucket,            'Key'        => $file['name'],            'SourceFile' => $file['file'],            'ContentDisposition' => 'attachment',        ) );

Thats it :)


Yes, you can set default Content-Disposition header for your each and every upcoming uploading file in your S3 bucket using Bucket Explorer's Bucket Default feature.

For existing files, you can use Update Metadata option that update metadata on every file exist in your bucket in batch.

You just need to -

Select Key as : Content-DispositionAdd Value as : attachment;filename={$file_name_without_path_$$}

Then update metadata on the files.

See this page to set Content-Disposition on your file.

More references:

Thanks