I am trying to use busboy-connect to parse my request file that I send to the server. When I print out my request object, I get this huge Angular.identity object and when I try and parse the object using this code:
app.post("/compositions/fileUpload", function(req, res){
var fstream;
req.pipe(req.busboy);
req.busboy.on('file', function (fieldname, file, filename) {
console.log("Uploading: " + filename);
fstream = fs.createWriteStream('/files/' + filename);
file.pipe(fstream);
fstream.on('close', function () {
res.redirect('back');
});
});
I error out on the "req.pipe(req.busboy)". I do require connect-busboy, and fs. I also make sure to tell my app to use busboy, so they should be there. However, I continue to get this error:
TypeError: Cannot call method 'on' of undefined
at IncomingMessage.Readable.pipe (_stream_readable.js:476:8)
at Object.handle (/home/cyen/development/composelet/source/composelet/packages/compositions/server/routes/compositions.js:38:10)
at next_layer (/home/cyen/development/composelet/source/composelet/node_modules/express/lib/router/route.js:103:13)
at Route.dispatch (/home/cyen/development/composelet/source/composelet/node_modules/express/lib/router/route.js:107:5)
at /home/cyen/development/composelet/source/composelet/node_modules/express/lib/router/index.js:213:24
at Function.proto.process_params (/home/cyen/development/composelet/source/composelet/node_modules/express/lib/router/index.js:286:12)
at next (/home/cyen/development/composelet/source/composelet/node_modules/express/lib/router/index.js:207:19)
at next (/home/cyen/development/composelet/source/composelet/node_modules/express/lib/router/index.js:182:38)
at next (/home/cyen/development/composelet/source/composelet/node_modules/express/lib/router/index.js:182:38)
at next (/home/cyen/development/composelet/source/composelet/node_modules/express/lib/router/index.js:182:38)
POST /compositions/fileUpload 500 136.347 ms - -
_stream_readable.js:483
dest.end();
^
TypeError: Cannot call method 'end' of undefined
at IncomingMessage.onend (_stream_readable.js:483:10)
at IncomingMessage.g (events.js:180:16)
at IncomingMessage.EventEmitter.emit (events.js:92:17)
at _stream_readable.js:920:16
at process._tickCallback (node.js:415:13)
and I have no idea why. It seems there is another similar question to mine here but it has not been solved yet. Would anyone know what this error could be caused by? Thanks!