-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upload using tus but serve files directly from s3 or using nginx without tus server #621
Comments
Hi, it would probably be nice to have storage information in the // Storage contains information about where the upload is stored. The exact values
// depend on the storage that is used and are not available in the pre-create hook.
// This example belongs to the file store.
"Storage": {
// For example, the filestore supplies the absolute file path:
"Type": "filestore",
"Path": "/my/upload/directory/14b1c4c77771671a8479bc0444bbc5ce",
// The S3Store and GCSStore supply the bucket name and object key:
"Type": "s3store",
"Bucket": "my-upload-bucket",
"Key": "my-prefix/14b1c4c77771671a8479bc0444bbc5ce"
} Then you can use
No, content-type MUST be set to
Yes with
Not immediately as a response from the tus server to a tus client. Although you could alter the metadata server-side to include the your CDN URL to make your client aware of it.
They are required unfortunately. |
@Murderlon Thanks for your inputs. I took some time to try out your suggestions: 1.
This makes sense. But the second upload param I received (with name 2.
Without a proper content type in s3, all files are downloaded automatically when accessed instead of rendering as images or something else. This is happening obviously because the content type in s3 is 3.
This works and makes sense as well. 4.
I am not sure if I fully understand you here. Do you mean to say that while returning the response from server when the upload finishes, I just add the cdn url in the response metadata? 5.
Okay. Can I instead force the info files to be stored into a separate folder or is it necessary for both the files (main file and info file) to be stored side by side? Further Question:
|
No I meant to say that tusd implements this into the upload model and tus Node.js does not (yet). So that would require a PR first before you have access. I can take a look at that.
When we create an upload in S3, we set the tus-node-server/packages/s3-store/index.ts Lines 522 to 524 in a0f9da1
You can change the status code, body, and headers in const server = new Server({
// ..
async onUploadFinish(req, res, upload) {
const url = await getURLForCDN(req, res, upload)
// any headers you may want too
const headers = {}
return { res, status_code: 200, headers, body: JSON.stringify({ url }) }
},
})
For now they are always stored together. Vast majority of use cases don't need it separate.
If the client doesn't send any metadata, you don't have any metadata on the server either. Make sure your client always sends it. |
@Murderlon Thanks again for your thorough response.
Yeah, that would be really helpful. Thanks.
Yes, this is what I meant originally: |
Yes you can: const server = new Server({
// ..
async onUploadCreate(req, res, upload) {
const contentType = await extractContentType(req, res, upload)
const metadata = { ...upload.metadata, contentType }
return { res, metadata }
},
}) |
const server = new Server({ Can this be done for the GCSStore plugin as well - I'm having a hard time figuring out how to set the contentType - I set it in the metaData on tusClient and it's in the metadata field but not being set properly in cloud bucket running to same problem as above |
Created an issue for it. |
I am using tus along with uppy client in react app for uploading files which is working great.
Objective:
But I do not want to use tus at all for serving my uploaded files. I want to serve files directly from s3 or from local file system using nginx (whichever datastore I use) without having to pass the request through tus server. I can obviously put both s3 and local file system behind cdn of my choice. I feel the real benefit of tus is while uploading files and not after that. It would be great if there is an easier way to decouple the serving of files part.
Issues:
application/offset+octet-stream
and hence the file is downloaded instead of being rendered as image which I think I can override using the contentType metadata in tus client. But is there a way to do this in tus node server automatically for all files based on original file mimetype or something?some-file-name-${unique_id}.jpg
. The combination of both file name and unique id can help prevent conflicts between multiple files. Also, the extension can help in identifying the type of file quickly.Current Code:
Note that I am storing files of each user separately in their own directory.
Would really appreciate any help in this direction. Thanks!
The text was updated successfully, but these errors were encountered: