Created
May 6, 2020 21:43
-
-
Save sayhicoelho/f6e2c076a9069b929e07c4e21b768850 to your computer and use it in GitHub Desktop.
Node.js & Multer check if file is present in the request.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = (req, res, next) => { | |
if (!req.file) { | |
res.status(422).json({ message: 'The file is required.' }); | |
} else { | |
next(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
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