flowjs / flow.js

A JavaScript library providing multiple simultaneous, stable, fault-tolerant and resumable/restartable file uploads via the HTML5 File API.
Other
2.96k stars 346 forks source link

v3 does not support pausing/resuming from stream #346

Closed drzraf closed 2 years ago

drzraf commented 3 years ago

The current pause process consist into aborting all ongoing XHR object. Conversely resume call Flow.upload() again which goes over each pending chunk.

In the case of ReadableStream we can not expect to read() twice a regular file (as expected by FlowChunk.send()). A possible implementation could conserve the XHR payload in order to recreate it again (instead of setting FlowChunk's XHR to null)

drzraf commented 3 years ago

I've a problem with the current code paths.

If I call await files[0].chunks[0].send(); (uploading only one chunk of one file), it'll call FlowChunk.doneHandler() which in turn calls parent's flowObj.uploadNextChunk() which read/consume/send all remaining chunks. It's a counter-intuitive design. Wouldn't we prefer a more predictable chaining process?

AidasK commented 3 years ago

I think you have mentioned this problem earlier. I agree that it can be improved

drzraf commented 3 years ago

I also wonder about the following: An xhr.error(); => doneHandler (status === 'error') => abort(true) Why not using the retry() logic? Eg: We may receive a 400 or Timeout error because of some bandwidth exhaustion and it's worth retrying don't you think?

drzraf commented 2 years ago

348 fixed it. Pause & resuming from stream now works.

The counter-intuitive pause()/resume() design can be solved in a subsequent issue.