2016-11-14 45 views
-1
app.use(bodyParser.urlencoded({ extended: false })); 
app.use(bodyParser.json()); 

app.post('/upload', function (req, res) { 
    console.log('hari :'+req.body.purpose); 
    timeNow = Date.now(); 
    var jobID = timeNow + '_' + Math.floor((Math.random() * 10000000000000) + 1); 
    var rethinkObj = config.rethinkdb; 
    var data = { 
    "id": jobID, 
    "finished_at": timeNow, 
    "last_update": timeNow, 
    "log": "add job", 
    "process_instructions": "", 
    "start_at": timeNow, 
    "status": "in-progress" 
    } 
    rethink.insertDataIntoTable(rethinkObj, data).then(function(insertedData){ 
    console.log(insertedData); 
    console.log('new row inserted into RethinkDB', data.id); 

    uploadFile(req, res, jobID); 

    }) 
}); 

回答

2

您應該添加一箇中間件來處理文件,因爲bodyParser不能使用它們。從bodyParser的自述文件引用:

由於它們非常複雜且通常很大,因此無法處理多部分機構。對於多機構,您可以在以下模塊感興趣:

  • 打雜和連接,打雜
  • 多方並連接多黨
  • 強大
  • multer