I am using Busboy
is store files in locally. below is my code:
apiRoutes.post('/upload' ,function(req, res){
var fstream;
req.pipe(req.busboy);
req.busboy.on('file', function (fieldname, file, filename) {
console.log("Uploading: " + filename);
//Path where image will be uploaded
fstream = fs.createWriteStream(__dirname + '/img/' + filename);
file.pipe(fstream);
fstream.on('close', function () {
console.log("Upload Finished of " + filename);
res.redirect('back');
});
});
});
This code is working fine in plain separate project. But when I am using this middleware in my project then its showing an error:
_stream_readable.js:498
dest.end();
TypeError: Cannot read property 'end' of undefined
at onend(_stream_readable.js:498:9)
at _combinedTickCallback(node.js:370:9)
at process._tickCallback(node.js:401:11)
I google it but didn't find any solution. Please have a look at this code and help me please.
Answer would be appreciated.
Thanks