# How to specify headers when using @tus/s3-store

**URL:** <https://community.transloadit.com/t/how-to-specify-headers-when-using-tus-s3-store/17463>\
**Category:** Tus\
**Created:** [February 10, 2025, 8:53am UTC](https://community.transloadit.com/t/how-to-specify-headers-when-using-tus-s3-store/17463 "2025-02-10T08:53:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![empz](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/empz/32/1269_2.png) [@empz](https://community.transloadit.com/u/empz)\
**Post date:** [February 10, 2025, 8:53am UTC](https://community.transloadit.com/t/how-to-specify-headers-when-using-tus-s3-store/17463/1 "2025-02-10T08:53:52Z")

</div>

I want to be able to set some default headers that will be applied to all uploads to the S3 store.

I also want to be able to set some headers dynamically based on the uploaded file extension and metadata sent by the client.

This should be pretty straightforward to do but I could not find anything in the documentation or codebase.

---

<div class="post-metadata">

**Author:** ![Merlijn](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/merlijn/32/1382_2.png) [@Merlijn](https://community.transloadit.com/u/Merlijn)\
**Post date:** [February 10, 2025, 8:58am UTC](https://community.transloadit.com/t/how-to-specify-headers-when-using-tus-s3-store/17463/2 "2025-02-10T08:58:10Z")

</div>

Have you tried using `onBeforeRequest`?

---

<div class="post-metadata">

**Author:** ![empz](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/empz/32/1269_2.png) [@empz](https://community.transloadit.com/u/empz)\
**Post date:** [February 10, 2025, 9:02am UTC](https://community.transloadit.com/t/how-to-specify-headers-when-using-tus-s3-store/17463/3 "2025-02-10T09:02:57Z")

</div>

> [@Merlijn](#):
>
> onBeforeRequest

But that’s on the Uppy.js client, right? Is it not possible to do it on the server?

---

<div class="post-metadata">

**Author:** ![empz](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/empz/32/1269_2.png) [@empz](https://community.transloadit.com/u/empz)\
**Post date:** [February 10, 2025, 9:07am UTC](https://community.transloadit.com/t/how-to-specify-headers-when-using-tus-s3-store/17463/4 "2025-02-10T09:07:43Z")

</div>

Besides, isn’t that to modify the request sent from the Uppy client to the Tus server? Are you sure the headers I set on that request are going to be written to the S3 file? Looks like the wrong place.

I just want an option to specify the headers that are written on the S3 object.

---

<div class="post-metadata">

**Author:** ![Merlijn](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/merlijn/32/1382_2.png) [@Merlijn](https://community.transloadit.com/u/Merlijn)\
**Post date:** [February 10, 2025, 9:07am UTC](https://community.transloadit.com/t/how-to-specify-headers-when-using-tus-s3-store/17463/5 "2025-02-10T09:07:57Z")

</div>

I mixed the two up for a second (it’s morning). I meant [onIncomingRequest](https://github.com/tus/tus-node-server/tree/main/packages/server#optionsonincomingrequest).

```js
onIncomingRequest(req, res) {
  res.setHeader('Something', 'foo')
}

```

But you want to set headers towards S3. That’s currently not possible.

---

<div class="post-metadata">

**Author:** ![empz](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/empz/32/1269_2.png) [@empz](https://community.transloadit.com/u/empz)\
**Post date:** [February 10, 2025, 9:12am UTC](https://community.transloadit.com/t/how-to-specify-headers-when-using-tus-s3-store/17463/6 "2025-02-10T09:12:44Z")

</div>

When using Transloadit, you do the following on a template.

```json
"exported": {
      "robot": "/minio/store",
      "use": ":original",
      "path": "${fields.userId}/${file.id}.${file.ext}",
      "credentials": "tigris_prod",
      "headers": {
        "Content-Type": "${file.mime}",
        "Cache-Control": "max-age=31536000"
      }
    }

```

I’m just looking to do the same when using Tus server with the S3Store.

```ts
const server = new Server({
  path: "/files",
  allowedOrigins: allowedOrigins,

  datastore: new S3Store({
    s3ClientConfig: {
      endpoint: S3_ENDPOINT,
      region: "auto",
      bucket: S3_BUCKET,
      credentials: {
        accessKeyId: process.env.S3_ACCESS_KEY_ID,
        secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
      },
    // set default headers here?
    },
  }),

  ...
})

```

---

<div class="post-metadata">

**Author:** ![empz](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/empz/32/1269_2.png) [@empz](https://community.transloadit.com/u/empz)\
**Post date:** [February 10, 2025, 9:13am UTC](https://community.transloadit.com/t/how-to-specify-headers-when-using-tus-s3-store/17463/7 "2025-02-10T09:13:52Z")

</div>

Pfff… okay, I’ll guess I’ll just use the FileStore and perform the upload to S3 myself.

---

<div class="post-metadata">

**Author:** ![Merlijn](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/merlijn/32/1382_2.png) [@Merlijn](https://community.transloadit.com/u/Merlijn)\
**Post date:** [February 10, 2025, 9:15am UTC](https://community.transloadit.com/t/how-to-specify-headers-when-using-tus-s3-store/17463/8 "2025-02-10T09:15:12Z")

</div>

If you only want those headers, they are already set if they are present on meta data:

> <https://github.com/tus/tus-node-server/blob/af6a55aea8724fea3894dc71eaced0a2c2427d82/packages/s3-store/src/index.ts#L547-L553>

---

<div class="post-metadata">

**Author:** ![Merlijn](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/merlijn/32/1382_2.png) [@Merlijn](https://community.transloadit.com/u/Merlijn)\
**Post date:** [February 10, 2025, 9:15am UTC](https://community.transloadit.com/t/how-to-specify-headers-when-using-tus-s3-store/17463/9 "2025-02-10T09:15:57Z")

</div>

PRs welcome to make it more clear in the `@tus/s3-store` docs
