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

Flow Options `target` wait until completes if a function #294

Open justinmusti opened 4 years ago

justinmusti commented 4 years ago

When assigning configuration, the documentation states that target property can be a function.

While utilizing it as a function, wait for it to complete or return a response before starting the upload process so a proper URL is returned.

USECASE:

  1. simultaneousUploads is set to something bigger than 1, let's say 5
  2. Flow starts uploading file in 5 chunks at a time.
  3. Server is now facing a race condition because the chunks are being sent simultaneously hence database entries are created at the same time causing duplicate entries.
  4. File upload process is now corrupted.

For a healthy way of implementation to ensure the race condition is averted with proper back-end reference to the file, allow the target option to be a function and wait until it returns a response, which is a unique url for the file to be uploaded to.

Problem

Currently the Flow object does not wait to start uploading the file until after the target function returns a response.