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

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.

Have you tried using onBeforeRequest?

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

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.

I mixed the two up for a second (it’s morning). I meant onIncomingRequest.

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

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

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

"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.

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?
    },
  }),

  ...
})

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

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

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