expressjs / expressjs/multer

limits - is there anyway to get all field limits error?

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

Description

- Let's say I have a config to limit each file's size to 5MB like this:
```javascript
import multer from 'multer';
const upload = multer({
storage: multer.memoryStorage(),
limits: {
fileSize: 500000, // 5MB
}
});
```

- Then I use it to handle `flagIcon` and `flagIcon2` files
```javascript
teamsRouter.post(
'/team',
upload.fields([
{ name: 'flagIcon', maxCount: 1 },
{ name: 'flagIcon2', maxCount: 1 },
]),
adminTeamController.createTeam,
(
req: express.Request,
res: express.Response,
next: express.NextFunction
) => {
// handle errors
if (error instanceof MulterError) {
return res.status(400).send(error);
}
res.status(500).send({ message: error.message });
}
);
```
- If I upload both of `flagIcon` and `flagIcon2` files with larger than 5MB images. I only get one error of `flagIcon` thrown:
```
{
"name": "MulterError",
"message": "File too large",
"code": "LIMIT_FILE_SIZE",
"field": "flagIcon",
"storageErrors": []
}
```
- Question: How can I get all errors thrown? In other words, how to keep upload process (of other fields) continue in case there is error from a field?

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.