Created
February 12, 2022 13:33
-
-
Save NikhilNanjappa/83dd71f1357c3bc83616fc89c13d8b03 to your computer and use it in GitHub Desktop.
handleMultipartFormData.js
This file contains hidden or 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 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