2016-03-04 56 views
0

下面的代碼上傳文件正確,但onFileUploadData永遠不會打。我曾嘗試實例與舊multer它似乎工作,但不是最新版本。有任何想法嗎?multer onFileUploadData不執行

//Server.js 
var express = require("express"); 
var multer = require('multer'); 
var app   = express(); 

app.use(multer({ 
    dest: './uploads/', 
    onFileUploadData:function(file, data, res, req){ 
     console.log('onFileUploadData'); 
    } 
}).single('userPhoto')); 



app.get('/',function(req,res){ 
     res.sendFile(__dirname + "/index.html"); 
}); 

app.post('/api/photo',function(req,res){ 

    console.log('ended'); 
    res.end("ended"); 

}); 

app.listen(3000,function(){ 
    console.log("Working on port 3000"); 
}); 

在的package.json文件:

{ 
    "name": "file_upload", 
    "version": "0.0.1", 
    "dependencies": { 
    "express": "4.13.4", 
    "multer": "1.1.0" 
    } 
} 

在視圖文件: //index.html

<html> 

<form id  = "uploadForm" 
     enctype = "multipart/form-data" 
     action = "/api/photo" 
     method = "post" 
> 
<input type="file" name="userPhoto" accept="application/x-zip-compressed,image/*"> 
<input type="submit" value="Upload Image" name="submit"> 
</form> 


</html> 

回答

0

的事件處理器已從Multer移除。