I am trying to download a program to download files. The code I'm using is
app.post('/photos',loadUser, function(req, res) { var post = new Post(); req.form.complete(function(err, fields, files) { if(err) { console.log(err); next(err); } else { ins = fs.createReadStream(files.file.path); ous = fs.createWriteStream(__dirname + '/public/uploads/photos/' + files.file.filename); post.filename=files.file.filename; post.file=files.file.path; util.pump(ins, ous, function(err) { if(err) { next(err); } else { post.save(function(err,docs) { req.flash('info', 'information Saved'); res.redirect('/photos'); }); } }); } }); });
When I remove the loadUser method, everything works fine, but when I use the loadUser
method, it gives me an error. Error Console Information:
Error: parser error, 0 of 4344 bytes parsed at IncomingForm.write (/home/darhamid/node_modules/formidable/lib/incoming_form.js:141:17) at IncomingMessage.<anonymous> (/home/darhamid/node_modules/formidable/lib/incoming_form.js:91:12) at IncomingMessage.emit (events.js:67:17) at HTTPParser.onBody (http.js:121:23) at Socket.ondata (http.js:1349:22) at TCP.onread (net_uv.js:312:27)
The error only occurs when I use the loadUser function, if I remove the Funciton bootloader, everything works fine. I do not know the reasons for this and got stuck. Can anybody help me?
source share