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

@uppy/xhr-upload: add 'upload-stalled' event #4247

Merged
merged 10 commits into from
Feb 1, 2023
5 changes: 1 addition & 4 deletions packages/@uppy/xhr-upload/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,8 @@ export default class XHRUpload extends BasePlugin {
let queuedRequest

const timer = new ProgressTimeout(opts.timeout, () => {
xhr.abort()
queuedRequest.done()
const error = new Error(this.i18n('timedOut', { seconds: Math.ceil(opts.timeout / 1000) }))
this.uppy.emit('upload-error', file, error)
reject(error)
this.uppy.emit('upload-stalled', file, error)
})

const id = nanoid()
Expand Down
13 changes: 13 additions & 0 deletions website/src/docs/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,19 @@ uppy.on('upload-error', (file, error, response) => {
})
```

### `upload-stalled`

Fired when an upload is seemingly stalled. Use this event to display a message on the UI to tell the user they might want to retry the upload.
aduh95 marked this conversation as resolved.
Show resolved Hide resolved

```js
uppy.on('upload-stalled', () => {
uppy.info(`Your upload "${file.meta.name}" has not made any progress for ${timeout} seconds. You may want to retry it.`, 'warning')
uppy.once('progress', () => {
stallWarning.hidden = true
aduh95 marked this conversation as resolved.
Show resolved Hide resolved
})
})
```

### `upload-retry`

Fired when an upload has been retried (after an error, for example).
Expand Down
4 changes: 2 additions & 2 deletions website/src/docs/xhr-upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ function getResponseError (responseText, response) {

The field name containing a publically accessible location of the uploaded file in the response data returned by [`getResponseData()`](#getResponseData-responseText-response).

### `timeout: 30 * 1000`
### `timeout: 30_000`

When no upload progress events have been received for this amount of milliseconds, assume the connection has an issue and abort the upload.
When no upload progress events have been received for this amount of milliseconds, send a `'upload-stalled'` event.
Note that unlike the [`XMLHttpRequest.timeout`][XHR.timeout] property, this is a timer between progress events: the total upload can take longer than this value.
Set to `0` to disable this check.

Expand Down