How can I modify HTTP Headers for Objects in my Bucket?

Linode Staff

Is there a way to change HTTP Response headers for images being served from object storage to specify how long the image should be cached by the browser?

2 Replies

You can do so using s3cmd to modify the metadata of either the entire bucket, or on a per object basis.

To make the change for all of the objects inside of the bucket you can do so by running the following command:

s3cmd --recursive modify --add-header=”Cache-Control: max-age=$TOTAL_SECONDS” s3://$BUCKET_NAME

To make the change on one file you can do so with the following command:

s3cmd modify --add-header=”Cache-Control: max-age=$TOTAL_SECONDS” s3://$BUCKET_NAME/$FILE_NAME

You can even use globbing to target files that have a particular extension to add the header:

s3cmd modify --add-header=”Cache-Control: max-age=$TOTAL_SECONDS” ‘s3://$BUCKET_NAME/*.png’

(Please note the single quotes surrounding the location of the bucket.)

$TOTAL_SECONDS, $BUCKET_NAME and $FILE_NAME are the number of seconds the browser should cache the file, the name of the bucket, and the name of the file respectively.

Hi, how can I ensure all the future files added to the storage has the expiration set to the headers? I am using s3 boto api to upload files to storage, do I need to set the expiration headers via my upload function?


Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct