2013-03-08 61 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

我试着删除“延迟:真正”的配置,它适用于我。