我对此代码有一个重要的问题
form
.on('error', function(err) {
throw err;
})
.on('field', function(field, value) {
//receive form fields here
})
/* this is where the renaming happens */
.on ('fileBegin', function(name, file){
//rename the incoming file to the file's name
file.path = form.uploadDir + "/" + file.name;
})
.on('file', function(field, file) {
//On file received
})
.on('progress', function(bytesReceived, bytesExpected) {
//self.emit('progess', bytesReceived, bytesExpected)
var percent = (bytesReceived / bytesExpected * 100) | 0;
process.stdout.write('Uploading: %' + percent + '\r');
})
这些是强大的模块的方法...我发现express.bodyParser使用强大的模块...但我想调用方法。('fileBegin'...用快递和我不能
方法在哪里......对象形式在哪里
如您所见,对象表单包含字段和文件
在express.bodyParser中,文件位于req.files中,字段位于req.body中 但是当我试着打电话给req.on('fileBegin'......给我一个错误
任何人都试试这个???
答案 0 :(得分:1)
defer
选项已添加到multipart
:
app.use(connect.multipart({ defer: true }));
...后来
app.post('/foo', function (request, response, next) {
// setting defer exposes multipart's internal IncomingForm object
var form = request.form;
});
答案 1 :(得分:0)
事实证明,formidable
对象只是connect.multipart
中的局部变量,永远不会附加到req
。看起来你必须使用connect.multipart
作为指南来推送自己的中间件(它实际上非常简短)。