tus / tus-js-client

A pure JavaScript client for the tus resumable upload protocol
https://tus.io/
MIT License
2.11k stars 316 forks source link

Resuming uploads with `uploadDataDuringCreation` resets uploads to latest chunk #494

Open JammingBen opened 2 years ago

JammingBen commented 2 years ago

Describe the bug When having the uploadDataDuringCreation option set to true, pausing and resuming an upload resets the upload to the latest successfully uploaded chunk. That's especially bad when no chunk has been uploaded yet, meaning the upload would start over.

To Reproduce

  1. Set uploadDataDuringCreation to true
  2. Set the chunk size to Infinite
  3. Start upload, wait a bit
  4. Pause it
  5. Resume it

Expected behavior The upload gets resumed right where it was paused.

Setup details

Acconut commented 2 years ago

This is not a bug but the expected behavior. If you set uploadDataDuringCreation and interrupt the upload before the initial POST request finishes, tus-js-client will not be able to receive the response. Therefore, it does not know the upload URL and cannot resume. Instead it must start a new upload.

You should only use uploadDataDuringCreation if it is acceptable for you to start a new upload in these cases. Note that you can also control the amount of data that is included in the initial POST request using the chunkSize option. It makes sense to limit the amount, so that you receive the upload URL before the entire file has been uploaded. For small files, you have the benefit of an upload in a single request, but for larger files you have the benefit of resumable uploads.