expressjs / expressjs/multer

Hangs when sending files and text fields

Open
#627 4 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

I'm able to get multer to upload a png image just fine, but when I try to upload jpeg images of varying sizes they all make multer hang. They pass the file size limit and fileFilter function. They all get saved into uploads/temp/. Multer just doesn't go to the next middleware!

Here's part of my code:

```
// route.js

const filesList = [
{
name: 'selfie',
maxCount: 1,
},
];

const maxFileSize = 2 * 1024 * 1024;

const upload = multer({
dest: 'uploads/temp',
limits: {
fileSize: maxFileSize,
},

fileFilter: (req, file, cb) => {
console.log('checking file types');
const supportedMimeTypes = [
'image/jpeg',
'image/png',
];
if (!supportedMimeTypes.includes(file.mimetype)) {
console.log('file type not supported');
cb(null, false);
return;
}

console.log('file: ', file);

// all images reach this far

cb(null, true);
},
}).fields(filesList);

const middleware = (req, res, next) => {
console.log('Parsing multipart');
upload(req, res, (err) => {
console.log('callback');

// jpeg images never reach this far, but png images do

if (err) {
console.log('Error from multer: ', err);
throw err;
}
next();
});
};
```

Contributor guide

Open the contributing guide

Research direction

Start with the upload middleware in route.js, especially the .fields(filesList) configuration and the callback that should invoke next(). Reproduce the difference between JPEG and PNG uploads while checking where processing stops. Done means the JPEG request completes and reaches the next middleware without breaking the existing file-size and MIME-type behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.