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

File added to "files" after fileAdded event fires #318

Open abulhol opened 3 years ago

abulhol commented 3 years ago

I want to run some checks when flow.on('fileAdded') is fired, for example comparing the file size with a threshold. In case the file is too big, I want to reject it and call flow.cancel(). However, the file is actually not in the flow.files list at that point. It is added directly afterwards, see flow.js:

        if (this.fire('fileAdded', f, event)) {
          files.push(f);
        }

So calling cancel() doesn't work, the file is added to the list and stays there.

This behavior has already led to unexpected behavior several times in my project.

I work around it by running the file size check at a later point, but isn't there a better way to handle this? Am I missing something?