I am using connect-busboy
in Express.js 4 in order to upload files. I have added app.use(busboy({ immediate: true });
in app.js. My route handler looks like this:
router.post('/upload', function (req, res) {
var fstream;
req.pipe(req.busboy);
console.log(req.busboy);
req.busboy.on('file', function (fieldName, file, fileName) {
console.log('Uploading ' + fileName + '...');
fstream = fs.createWriteStream(__dirname + '/data/' + fileName);
file.pipe(fstream);
fstream.on('close', function () {
res.end('ok');
});
});
});
The console.log(req.busboy);
returns undefined
. Why?!??!
Sorted it out! It turns out that the contentType
should be form/multi-part
, which wasn't the case