Skip to content
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

Custom file names #30

Merged
merged 20 commits into from
May 23, 2016
Merged

Custom file names #30

merged 20 commits into from
May 23, 2016

Conversation

js3692
Copy link
Contributor

@js3692 js3692 commented May 20, 2016

User can now provide a hashing function to set a custom file name for each upload. When the hashing function is not provided, it defaults to a random Uid.

Example:

const fileNameFromUrl = (req) => {
    return req.url.replace(/\//g, '-');
}

server.datastore = new tus.FileStore({
    path: '/files',
    namingFunction: fileNameFromUrl
});

Assuming the POST request was made to /files, the file name will now be '-file'

@coveralls
Copy link

Coverage Status

Coverage decreased (-53.4%) to 30.315% when pulling 52792aa on js3692:custom-filenames into 16fbee5 on tus:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+2.5%) to 86.22% when pulling c5f3a5f on js3692:custom-filenames into 16fbee5 on tus:master.

@@ -11,7 +11,7 @@ class HeadHandler extends BaseHandler {
* @return {function}
*/
send(req, res) {
const re = new RegExp('\\' + this.store.path + '\\/(\\w+)\/?'); // eslint-disable-line prefer-template
const re = new RegExp('\\' + this.store.path + '\\/([\\w\-]+)\/?'); // eslint-disable-line prefer-template
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added just for that example hashing function from our convo on the issue, right? Maybe it should just match the non-whitespace (\S) rather than any alphanumeric character.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that was to match the example function from the issue. I think \S would be more concise too :)

@coveralls
Copy link

Coverage Status

Coverage decreased (-30.4%) to 63.06% when pulling bb77f6e on js3692:custom-filenames into 74f3ac7 on tus:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.0%) to 92.537% when pulling 3b6a64e on js3692:custom-filenames into 74f3ac7 on tus:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.8%) to 94.34% when pulling 5e3d145 on js3692:custom-filenames into 74f3ac7 on tus:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.8%) to 94.318% when pulling c504c55 on js3692:custom-filenames into 74f3ac7 on tus:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.8%) to 94.318% when pulling e5e6fd5 on js3692:custom-filenames into 74f3ac7 on tus:master.

const upload_metadata = req.headers['upload-metadata'];

if (upload_length === undefined && upload_defer_length === undefined) {
return reject(412);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These error code/messages should probably be constants, but I can do that in a separate PR :)

@bhstahl
Copy link
Contributor

bhstahl commented May 23, 2016

Thanks @js3692 !!

@bhstahl bhstahl merged commit e6b4c00 into tus:master May 23, 2016
@avillarubia
Copy link

only renames to - hypen without extension. What I need is to save the file to its original name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants