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

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

Open
abulhol opened this issue Sep 22, 2020 · 0 comments
Open

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

abulhol opened this issue Sep 22, 2020 · 0 comments

Comments

@abulhol
Copy link

abulhol commented Sep 22, 2020

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?

drzraf pushed a commit to drzraf/flow.js that referenced this issue Oct 12, 2020
…total amount of bytes to upload.

The number of chunks may also be off. Let fail safely:
- if read using an async function
- and the last chunk read less bytes than usual (including 0)
- and the current chunk read no byte
- assume that this chunk is in fact superfluous and simulate its completion.

Previous discussion on:
flowjs#42
flowjs#318

In the long-term Flow.js may have to support the concept of "approximate chunk number".
drzraf pushed a commit to drzraf/flow.js that referenced this issue Oct 13, 2020
…total amount of bytes to upload.

The number of chunks may also be off. Let fail safely:
- if read using an async function
- and the last chunk read less bytes than usual (including 0)
- and the current chunk read no byte
- assume that this chunk is in fact superfluous and simulate its completion.

Previous discussion on:
flowjs#42
flowjs#318

In the long-term Flow.js may have to support the concept of "approximate chunk number".
drzraf pushed a commit to drzraf/flow.js that referenced this issue Oct 15, 2020
Since implementing a good concurrency-handler may be painful we
 provide a promise-based read-locking one so that asyncReadFileFn
 is safe to use out-of-the-box.

Given that streams-read are often unable to correctly/exactly compute their
 final amount of bytes to upload, the number of chunks may also be off.
 We handle this in a safe way via FlowChunk.readBytes:
- if read using an async function
- and the last chunk read less bytes than usual (including 0)
- and the current chunk read no byte
- assume that this chunk is in fact superfluous and simulate its completion.

Previous discussion on:
* flowjs#42
* flowjs#318
(In the long-term Flow.js may have to support the concept of "approximate chunk number")
drzraf pushed a commit to drzraf/flow.js that referenced this issue Oct 15, 2020
Since implementing a good concurrency-handler may be painful we
 provide a promise-based read-locking one so that asyncReadFileFn
 is safe to use out-of-the-box.

Given that streams-read are often unable to correctly/exactly compute their
 final amount of bytes to upload, the number of chunks may also be off.
 We handle this in a safe way via FlowChunk.readBytes:
- if read using an async function
- and the last chunk read less bytes than usual (including 0)
- and the current chunk read no byte
- assume that this chunk is in fact superfluous and simulate its completion.

Previous discussion on:
* flowjs#42
* flowjs#318
(In the long-term Flow.js may have to support the concept of "approximate chunk number")
drzraf added a commit that referenced this issue Dec 31, 2020
Support async function for readFileFn

Since implementing a good concurrency-handler may be painful we provide a promise-based read-locking one so that asyncReadFileFn is safe to use out-of-the-box.

Given that streams-read are often unable to correctly/exactly compute their final amount of bytes to upload, the number of chunks may also be off. We handle this in a safe way via FlowChunk.readBytes:
- if read using an async function
- and the last chunk read less bytes than usual (including 0)
- and the current chunk read no byte
- assume that this chunk is in fact superfluous and simulate its completion.

Previous discussion on:
* #42
* #318
(In the long-term Flow.js may have to support the concept of "approximate chunk number")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant