3

In client I use XHR2 Formdata to upload file in ajax:

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);

in node.js server:

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");
})

the strange thing is, the file could upload successfully, it can't log the req.files and req.body information, they are all empty object

so how can I get the upload file's information, like the save path, size or name?

4

1 回答 1

0

我尝试删除“defer:true”配置,它对我有用。

于 2013-06-19T07:01:14.743 回答