multer
multer copied to clipboard
limits - is there anyway to get all field limits error?
- Let's say I have a config to limit each file's size to 5MB like this:
import multer from 'multer';
const upload = multer({
storage: multer.memoryStorage(),
limits: {
fileSize: 500000, // 5MB
}
});
- Then I use it to handle
flagIcon
andflagIcon2
files
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
andflagIcon2
files with larger than 5MB images. I only get one error offlagIcon
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?
Sorry for the late reply. This is not currently supported since the we stop reading from the stream when we encounter the limit.
We could potentially implement this by keeping the stream open and scan it without saving the data 🤔