Node.js可以';无法读取XHR2 FormData数据
在客户端中,我使用XHR2Node.js可以';无法读取XHR2 FormData数据,node.js,file-upload,xmlhttprequest,form-data,Node.js,File Upload,Xmlhttprequest,Form Data,在客户端中,我使用XHR2Formdata在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', _fi
Formdata
在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);
在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.files
和req.body
信息,它们都是空对象
因此,如何获取上传文件的信息,如保存路径、大小或名称?我尝试删除“延迟:true”配置,它对我很有效