Skip to content

Instantly share code, notes, and snippets.

@sayhicoelho
Created May 6, 2020 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sayhicoelho/f6e2c076a9069b929e07c4e21b768850 to your computer and use it in GitHub Desktop.
Save sayhicoelho/f6e2c076a9069b929e07c4e21b768850 to your computer and use it in GitHub Desktop.
Node.js & Multer check if file is present in the request.
module.exports = (req, res, next) => {
if (!req.file) {
res.status(422).json({ message: 'The file is required.' });
} else {
next();
}
}
// ...
const ensureFileIsPresent = require('./middleware/ensureFileIsPresent');
router.post(upload.single('file'), ensureFileIsPresent, exampleController.doSomething);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment