Skip to content

Instantly share code, notes, and snippets.

@NikhilNanjappa
Created February 12, 2022 13:33
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 NikhilNanjappa/83dd71f1357c3bc83616fc89c13d8b03 to your computer and use it in GitHub Desktop.
Save NikhilNanjappa/83dd71f1357c3bc83616fc89c13d8b03 to your computer and use it in GitHub Desktop.
handleMultipartFormData.js
const formidable = require('formidable');
module.exports = function (req, res, next) {
const formData = new formidable.IncomingForm();
formData
.parse(req, (err, fields, files) => {
if (err) {
next(err);
} else {
req.body = fields;
req.files = files;
next();
}
})
.on('error', err => {
next(err);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment