Storage & backups

Object Headers

1 min read

Each object stores HTTP headers that are returned when the object is downloaded. They tell the browser how to display the file and how long to cache it. You can also store your own metadata with an object.

The examples use AWS CLI configured for UzCloud. Replace my-bucket with the name of your bucket.

HeaderWhat it doesExample
Content-TypeFile typeimage/png, text/html; charset=utf-8
Cache-ControlBrowser and CDN cachingpublic, max-age=86400
Content-DispositionDownload instead of opening, file nameattachment; filename="report.pdf"
Content-EncodingCompressed contentgzip
x-amz-meta-*Your own metadatax-amz-meta-author: Demo

Set Headers on Upload

aws s3 cp ./logo.png s3://my-bucket/img/logo.png \
  --content-type image/png \
  --cache-control "public, max-age=31536000" \
  --metadata author=Demo

When you upload a folder, AWS CLI sets Content-Type automatically by file extension. You can set the same Cache-Control for all files:

aws s3 sync ./static s3://my-bucket/static/ --cache-control "public, max-age=86400"

View Headers

aws s3api head-object --bucket my-bucket --key img/logo.png

Change Headers of an Existing Object

Headers cannot be edited in place. Copy the object onto itself with new headers:

aws s3api copy-object --bucket my-bucket --key docs/report.pdf \
  --copy-source my-bucket/docs/report.pdf \
  --metadata-directive REPLACE \
  --content-type application/pdf \
  --content-disposition 'attachment; filename="report.pdf"'

Note

With --metadata-directive REPLACE, all headers and metadata that you don’t specify are reset. List all the headers you need in the command.

Tip

See also: