expressjs / expressjs/multer

fileFilter not working

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

Description

I 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.

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.