expressjs / expressjs/multer

fileFilter is not returning with cb() until upload completes, even when rejected or error is thrown

Open
#975 2 comments 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
12.1k
Forks
1.1k
Avg merge
8d 2h
Merged PRs (30d)
21

Description

This issue was [brought up once before](https://github.com/expressjs/multer/issues/525) however it was closed because it was supposedly related to issue #344, but I don't believe that to be the case.

Here's the problem. I'm using `fileFilter` to attempt to validate files. If a file is not valid, I attempt to call `cb(null, false)` to reject the file or `cb(new Error('File not permitted.'))` to throw an error. Calling either of these doesn't seem to return control to the route's main function until the upload completes. Therefore, even though I know a file is not valid, the file continues to upload to 100% before server actually rejects it and informs the user.

Supposedly, this was related to using the [`limits` property problem](https://github.com/expressjs/multer/issues/344), however I've completely eliminated `limits` and I am still experiencing this issue.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.