multer icon indicating copy to clipboard operation
multer copied to clipboard

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

Open danieldilly opened this issue 4 years ago • 2 comments

This issue was brought up once before 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, however I've completely eliminated limits and I am still experiencing this issue.

danieldilly avatar Jan 20 '21 17:01 danieldilly

Yeah I'm also encountering this. Is it really a desired/expected behavior? It seems strange that files are being uploaded even when fileFilter’s cb is called with acceptFile: false or exception.

katibov avatar Jun 27 '22 00:06 katibov

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.

Hmm, this doesn't match what I'm used to. Do you have an express error handler attached that doesn't get called?

Could you provide a minimal reproducible example?

LinusU avatar Oct 30 '22 14:10 LinusU