Skip to content

Commit

Permalink
Add support for opts.headers as a function in @uppy/tus (#3221)
Browse files Browse the repository at this point in the history
  • Loading branch information
danilat committed Sep 29, 2021
1 parent d690315 commit 8b8783b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/@uppy/tus/src/index.js
Expand Up @@ -185,6 +185,10 @@ module.exports = class Tus extends BasePlugin {
...(file.tus || {}),
}

if (typeof opts.headers === 'function') {
opts.headers = opts.headers(file)
}

/** @type {RawTusOptions} */
const uploadOptions = {
...tusDefaultOptions,
Expand Down
22 changes: 21 additions & 1 deletion website/src/docs/tus.md
Expand Up @@ -47,7 +47,25 @@ Destination URL for your uploads. This should be where your tus.io server is run

### `headers: {}`

Additional request headers to send to the Tus endpoint when making requests.
An object containing additional HTTP headers to send to the Tus endpoint when making requests.
Keys are header names, values are header values.

```js
const headers = {
authorization: `Bearer ${window.getCurrentUserToken()}`,
}
```

Header values can also be derived from file data by providing a function. The function receives a [File Object][File Objects] and must return an object where the keys are header names, and values are header values.

```js
const headers = (file) => {
return {
authorization: `Bearer ${window.getCurrentUserToken()}`,
expires: file.meta.expires,
}
}
```

### `chunkSize: Infinity`

Expand Down Expand Up @@ -80,3 +98,5 @@ Pass an array of field names to limit the metadata fields that will be added to
Limit the amount of uploads going on at the same time. Setting this to `0` means there is no limit on concurrent uploads.

[tus-js-client]: https://github.com/tus/tus-js-client

[File Objects]: /docs/uppy/#File-Objects

0 comments on commit 8b8783b

Please sign in to comment.