---
title: "Setting Object Headers in S3 | Hostman Docs"
description: "Let's see how you can set object headers for S3 storage with Hostman’s guides. Optimize delivery and configure metadata effectively."
---

> For the complete documentation index for AI agents, see [llms.txt](https://hostman.com/llms.txt).

This guide explains how to set headers for [S3](https://hostman.com/products/s3-storage/) objects using `s3cmd` and `aws s3api`. This is useful for managing caching, adding custom metadata, and optimizing bucket data handling.

## Setting Headers via Dashboard

1.  Go to the **S3 storage** section and click on the bucket.
2.  In the **Objects** tab, click on the three dots next to the object and select **Edit metadata**.

![36d71125 Cdfd 41b2 9810 540c7c9b4883](https://content.hostman.com/assets/27221b6d-52c6-4d89-932f-793afd7572c1.png?width=1543&height=868)

3.  Add necessary headers. To set up a custom header, click **+Add**.

![Bacf7b83 9ffc 4c5b Ac07 5dd516c23d0d](https://content.hostman.com/assets/50adcfe9-1085-4745-ae5f-1ccdc80ef565.png?width=1548&height=867)

### Available Parameters

You can configure the following parameters.

#### Content-Type

The MIME type of the object's content. It defines the file format and is used by client applications to process the file correctly.

Example values:

-   `application/pdf`: PDF document
-   `image/jpeg`: JPEG image
-   `text/plain`: plain text file
-   `application/json`: JSON document

If an incorrect value is set, browsers or applications may fail to identify the file type properly.

#### Cache-Control

Controls how the object is cached by browsers, CDNs, and intermediate proxy servers.

Example: `max-age=3600`

In this case, the object can be stored in cache for 3600 seconds (1 hour) without making a new request to the storage.

#### Content-Encoding

Specifies the encoding applied to the object's content.

Example: `gzip`

Used for files that were compressed before being uploaded to storage. When the object is retrieved, the client can automatically decompress the content.

#### Content-Disposition

Defines how the file is handled when downloaded.

Common values:

-   `attachment`: prompt the user to save the file
-   `inline`: attempt to open the file directly in the browser

For example, for PDF documents, inline opens the file in a browser tab, while attachment triggers a download.

#### Custom Metadata

Lets you attach arbitrary key-value pairs to an object.

To add custom metadata, click **Add** and fill in the fields:

-   `Key`: the metadata name. Custom metadata keys are stored with the `x-amz-meta-` prefix.
-   `Value`: an arbitrary metadata value.

Examples:

| **Key** | **Value** |
| --- | --- |
| `project` | `website` |
| `owner` | `marketing` |
| `version` | `1.2` |

You can add multiple custom metadata entries to a single object.

Custom metadata does not affect file contents, but can be used by applications to store additional information about an object, classify it, or drive processing logic.

## Setting Headers via CLI

Another way to configure headers is to use utilities like `s3cmd` or `s3api`.

### Setting a Header for a Single Object

To set a header for a specific object, use the `s3cmd modify` command. For example, to add a Cache-Control header to a specific object:

```shell
s3cmd modify s3://<bucket_name>/<object_name> --add-header="cache-control:max-age=7000"
```

In this case, the object will receive the `Cache-Control` header with the `max-age=7000` parameter, instructing browsers or proxy servers to cache the object for 7000 seconds.

### Setting Headers for All Objects in a Bucket

To set headers for all objects in a bucket, you can use the `--recursive` option to apply changes to all files:

```shell
s3cmd modify --recursive s3://<bucket_name> --add-header="cache-control:max-age=7001"
```

This command recursively adds the `Cache-Control` header with the value `max-age=7001` to all objects in the bucket.

### Creating a Custom Header

To add custom headers, use the `s3cmd modify` command with the `x-amz-meta` prefix:

```shell
s3cmd modify s3://<bucket_name>/<object_name> --add-header="x-amz-meta-test-header:test"
```

This creates a custom header `x-amz-meta-test-header` with the value `test`. In the object's metadata, the header will appear without the `x-amz-meta-` prefix, resulting in:

```shell
"Metadata": {
    "test-header": "test"
}
```

This allows you to store additional data in the object, which can be useful for processing or logging.

### Verifying Set Headers

To verify the headers, use the `aws s3api head-object` command. This ensures that all headers and metadata have been successfully added:

```shell
aws s3api head-object --bucket <bucket_name> --key <object_name> --endpoint-url https://s3.hmstorage.net
```

The command will return information about the object, including its metadata and headers, allowing you to confirm that the changes were applied correctly.
