-
Notifications
You must be signed in to change notification settings - Fork 195
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
Allow for custom file names #25
Comments
Great! I would love to help out with this one, if it wasn't already picked up. My thoughts right now is to pass an options parameter to the app.post('/api/videos/tus-upload', function(req, res) {
server.handle(req, res, { filename: '50554d63-29bb-11e5-b345-feff819cdc9f' });
}); And either override the File id or instantiate with a file name in the POST handler: send(req, res, options) {
[...]
if (options && options.filename) {
file.id = options.filename;
}
OR
// filename would be '50554d63-29bb-11e5-b345-feff819cdc9f'
// When undefined the constructor would default it to Uid
const file = new File(upload_length, upload_defer_length, filename);
[...]
} @bhstahl What are your thoughts? |
Sure! Feel free to open a PR from your fork. While your suggestion works well for express, it doesn't really make sense for a standalone server that isn't planning on intercepting every request. I wonder if it could be even simpler. You're going to have some sort of hashing function to generate the file name anyhow, right? What if // Datastore.js
class DataStore {
constructor(options) {
this.generateFileName = options.namingFunction || Uid.rand;
}
create(req) {
const file_name = this.generateFileName(req);
//...
}
}
// your_server_implementation.js
const fileNameFromUrl = (req) => {
return req.url.replace(/\//g, '-');
}
server.datastore = new tus.FileStore({
path: '/files',
namingFunction: fileNameFromUrl
}); What do you think @js3692 ? |
Thanks for the comments! I'll open a PR soon. Yes, I think your suggestion makes better sense for standalone servers to take the hashing function. It could also allow express to flexibly attach the file name to I've implemented the |
closed in #30 |
sorry but req.filename is undefined |
Implementations should be able to provide filename for
POST
requests, and only if it is not provided, it can default back toUid
.Thanks for the suggestion @js3692!
The text was updated successfully, but these errors were encountered: