Skip to content

Commit

Permalink
Improve docs on namingFunction
Browse files Browse the repository at this point in the history
Closes tus#108
  • Loading branch information
Murderlon committed Mar 1, 2022
1 parent 0ab9cae commit f703b66
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,21 @@ server.get('/uploads', (req, res) => {
```
#### Custom file names:
The default naming of files is a random crypto hex string. When using your own `namingFunction`, make sure to create URL friendly names such as removing spaces.
```js
const fileNameFromUrl = (req) => {
return req.url.replace(/\//g, '-');
const crypto = require('crypto');

// req is http.IncomingMessage
const randomString = (req) => {
// same as the default implementation
return crypto.randomBytes(16).toString('hex');
}

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

0 comments on commit f703b66

Please sign in to comment.