考虑一个接收文件上传的 ExpressJS 应用程序:
app.post('/api/file', function(req, res) {
req.on('data', function() {
console.log('asd')
})
})
我不明白为什么永远不会触发数据事件。我还在使用 bodyParser() 中间件,它为每个文件提供了以下对象,这些文件似乎有一些可用的事件,但仍然没有效果:
{
file: {
domain: null,
_events: {},
_maxListeners: 10,
size: 43330194,
path: 'public/uploads/a4abdeae32d56a2494db48e9b0b22a5e.deb',
name: 'google-chrome-stable_current_amd64.deb',
type: 'application/x-deb',
hash: null,
lastModifiedDate: Sat Aug 24 2013 20: 59: 00 GMT + 0200(CEST),
_writeStream: {
_writableState: [Object],
writable: true,
domain: null,
_events: {},
_maxListeners: 10,
path: 'public/uploads/a4abdeae32d56a2494db48e9b0b22a5e.deb',
fd: null,
flags: 'w',
mode: 438,
start: undefined,
pos: undefined,
bytesWritten: 43330194,
closed: true,
open: [Function],
_write: [Function],
destroy: [Function],
close: [Function],
destroySoon: [Function],
pipe: [Function],
write: [Function],
end: [Function],
setMaxListeners: [Function],
emit: [Function],
addListener: [Function],
on: [Function],
once: [Function],
removeListener: [Function],
removeAllListeners: [Function],
listeners: [Function]
},
open: [Function],
toJSON: [Function],
write: [Function],
end: [Function],
setMaxListeners: [Function],
emit: [Function],
addListener: [Function],
on: [Function],
once: [Function],
removeListener: [Function],
removeAllListeners: [Function],
listeners: [Function]
}
}
我想了解如何取得进展并完成活动。