我可以解析我的多部分数据,但不能解析与表单一起提供的常规输入信息。我有一个word文档被上传,我可以解析,但我不能从输入文本类型中获取信息。我将请求发布到服务器,它到达那里,除了请求对象非常奇怪,因为Angularjs本身不支持多部分提交,我不得不将请求发布为angular.identity。我使用busboy-connect来解析多部分信息,所以我的方法看起来有点像这样:
req.pipe(req.busboy);
req.busboy.on('file', function (fieldname, file, filename) {
//this code parses the file
}
但是,每当我尝试使用req.name或req.param(name)时,我会一直得到undefined或null。有没有办法在bodyParser和busboy之间切换?我在底部打印出了JSON请求。
干杯
{ _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' } } }