I can parse my multi-part data, but not my regular input information that goes along with the form. I have a word document being uploaded, which I can parse fine, but I can't grab the information from the input text types. I post the request to the server, and it gets there, except the request object is very weird because Angularjs does not support multi-part submission natively, and I had to post the requesting as an angular.identity. I am using busboy-connect to parse the multi part information, so my method looks a little like this:
req.pipe(req.busboy);
req.busboy.on('file', function (fieldname, file, filename) {
//this code parses the file
}
However, whenever I try I try req.name, or req.param(name), I keep getting either undefined or null. Is there a way I can switch between bodyParser and busboy? I've printed out the request as JSON at the bottom.
Cheers
{ _writableState:
{ highWaterMark: 16384,
objectMode: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
decodeStrings: true,
defaultEncoding: 'utf8',
length: 0,
writing: false,
sync: true,
bufferProcessing: false,
onwrite: [Function],
writecb: null,
writelen: 0,
buffer: [] },
writable: true,
domain: null,
_events:
{ unpipe: [Function: onunpipe],
drain: [Function],
error: [Function: onerror],
close: { [Function: g] listener: [Function: onclose] },
finish: { [Function: g] listener: [Function: onfinish] } },
_maxListeners: 10,
_done: false,
_parser:
{ _needDrain: false,
_pause: false,
_cb: undefined,
_nparts: 0,
_boy: [Circular],
parser:
{ _writableState: [Object],
writable: true,
domain: null,
_events: [Object],
_maxListeners: 10,
_bparser: [Object],
_headerFirst: undefined,
_dashes: 0,
_parts: 0,
_finished: false,
_realFinish: false,
_isPreamble: true,
_justMatched: false,
_firstWrite: true,
_inHeader: true,
_part: undefined,
_cb: undefined,
_ignoreData: false,
_partOpts: {},
_pause: false,
_hparser: [Object] } },
opts:
{ headers:
{ host: 'localhost:3000',
connection: 'keep-alive',
'content-length': '44520',
accept: 'application/json, text/plain, */*',
origin: 'http://localhost:3000',
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36',
'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryyUi7ZbB4IU8PXkzm',
referer: 'http://localhost:3000/',
'accept-encoding': 'gzip,deflate,sdch',
'accept-language': 'en-US,en;q=0.8,it;q=0.6,es;q=0.4',
cookie: 'connect.sid=s%3AZpb0Vg74dgR-1iz3-bXPKhKnZyC9UY4U.uPvsAKswVQStlkMkDAv%2F%2BBIVA1rFzPC63xdZT5b7dnk' } } }
You need to listen for the 'field' event as well to catch non-file types. See the examples here.