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

Started by empz8 replies175 views
empzOriginal post
#1

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.

MerlijnTransloadit team
#2

Have you tried using onBeforeRequest?

#3

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

#4

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.

MerlijnTransloadit team
#5

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.

empz
#6

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

  ...
})
#7

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

MerlijnTransloadit team
#8

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

MerlijnTransloadit teamReplying to #8
#9

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