2013-03-08 99 views
3

在客戶端我用XHR2 Formdata上傳在AJAX文件:的Node.js無法讀取XHR2 FORMDATA數據

var send = function (file) { 
     var xhr = new XMLHttpRequest(); 
     xhr.file = file; 
     xhr.open('post', '/upload', true); 
     xhr.send(file);  
} 

var fd = new FormData(); 
fd.append('image', _file); // the _file is my file 

xhr.send(fd); 

中的node.js服務器:

app.configure(function(){ 
    app.use(express.bodyParser({ 
     uploadDir: "public/images", 
     keepExtensions: true, 
     limit: 10000000, /* 10M 10*1000*1000 */ 
     defer: true 
    })); 
    app.use(express.static(__dirname + "/public")); 
}); 



app.post("/upload", function (req, res) { 
    console.log(req.files); 
    console.log(req.body); 

    res.send("ok"); 
}) 

奇怪的是,該文件可以成功上傳,它不能登錄req.filesreq.body信息,它們都是空的對象

所以我怎樣才能得到上傳文件的信息,就像保存路徑,大小或名稱?

回答

0

我試着刪除「延遲:真正」的配置,它適用於我。