fileFilter not working
See original GitHub issueI wrote about this here https://github.com/expressjs/multer/issues/192
I have multer 1.0.6 , node 4.1.2, express 4.13.3
And this in file filter:
fileFilter: function (req, file, cb) {
// The function should call `cb` with a boolean
// to indicate if the file should be accepted
// To reject this file pass `false`, like so:
if (file.mimetype !== 'image/png'
&& file.mimetype !== 'image/jpg'
&& file.mimetype !== 'image/jpeg'
&& file.mimetype !== 'image/gif') {
console.log('Got file of type', file.mimetype);
return cb(new Error('Only image files are allowed!'));
}
// To accept the file pass `true`, like so:
cb(null, true);
}
When I send image file, everything works properly. But when I send something else like blabla.txt I expect error to return, but the request goes pending… in Chrome it says it is pending. After a couple of minutes I get response with net::ERR_EMPTY_RESPONSE.
I tried calling only
cb(new Error('Only image files are allowed!'));
without return
statement, same issue.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Multer: fileFilter not working - node.js - Stack Overflow
I'm using multer to upload files. everything is goung fine but fileFilter is not working. I've no idea where i'm going wrong. routes.js...
Read more >Express multer middleware
NOTE: Multer will not process any form which is not multipart ( multipart/form-data ). ... fileFilter, Function to control which files are accepted....
Read more >Copy files file filter not working as expected - Forum - VisualCron
In the Copy files task, on the Include file mask of the Location File filter, I have Point_UDI*.csv When I show filtered files...
Read more >filefilter not working with runModels() (MplusAutomation)
But does not work for the inputs with a filter for the first four characters of the file (Lev1), like this: runModels("C:/ICCproj/Inputs3", recursive=TRUE ......
Read more >Simple file filter is not working in - Bug Reports - Alfred Forum
But when I create a simple workflow with "File Filter", to this directory "~/Library/Cloudstorage/Dropbox" It does not work.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello, This was happening to me, this is how I fix it,
This help me process the error created if the fileFilter is false.
hope it helps.
@srkkhan you’ve added the same wrong hint there (https://github.com/expressjs/multer/issues/114), but it is not safe to test a file by its filename extension, it has to be done by its mime type. That said, @tim-montague last answer on #114 has no real effects on my side 😕. Some has changed and things needs to be done another way ?