Skip to content

Instantly share code, notes, and snippets.

@hdd42

hdd42/multiparty.js

Last active May 20, 2020
Embed
What would you like to do?
app.use((req,res,next)=>{
console.log("req.headers", req.headers['content-type'])
if (req.path=='/formDataRoute') {
const formData = new multiparty.Form();
formData.parse(req, (err,fields,files) =>{
if (err) {
console.log(err)
req.body =undefined;
}else{
req.body = {fields, files}
}
next()
})
}else{
next()
}
})
app.use(bodyParser.json({ limit: '50mb' }));
app.use(bodyParser.urlencoded({
extended: true
}));
app.post('/formDataRoute',(req,res,next) =>{
let {fields, files} = req.body;
console.log("Fields", fields)
console.log("files : ", files)
res.send('ok')
})
*** ornek express route log
Fields { ali: [ 'veli' ] }
files : {
dosya: [
{
fieldName: 'dosya',
originalFilename: 'a-common-sense-guide-to-data-structures-and-algorithms-second-edition_b11_0.pdf',
path: 'C:\\Users\\xhd\\AppData\\Local\\Temp\\6wyzBMkGCghKWrNxAihSNJL7.pdf',
headers: [Object],
size: 7994717
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment