empz
February 10, 2025, 8:53am
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.
Merlijn
February 10, 2025, 8:58am
2
Have you tried using onBeforeRequest
?
empz
February 10, 2025, 9:02am
3
Merlijn:
onBeforeRequest
But that’s on the Uppy.js client, right? Is it not possible to do it on the server?
empz
February 10, 2025, 9:07am
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.
Merlijn
February 10, 2025, 9:07am
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
February 10, 2025, 9:12am
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?
},
}),
...
})
empz
February 10, 2025, 9:13am
7
Pfff… okay, I’ll guess I’ll just use the FileStore and perform the upload to S3 myself.
Merlijn
February 10, 2025, 9:15am
8
If you only want those headers, they are already set if they are present on meta data:
Merlijn
February 10, 2025, 9:15am
9
PRs welcome to make it more clear in the @tus/s3-store
docs