app.js
app.get('/upload',upload.getPostFile);
app.post('/upload',upload.postFile);
upload.ejs
<form action="" enctype="multipart/form-data" method="post">
<input type="text" name="title"><br>
<input type="file" name="upload" multiple="multiple"><br>
<input type="submit" value="Upload">
</form>
upload.js
var multiparty = require('multiparty');
var util = require('util');
exports.getPostFile = function(req, res){
res.render('upload',{ title:"上传"});
};
exports.postFile = function(req,res){
var form = new multiparty.Form();
form.parse(req, function(err, fields, files) {
res.writeHead(200, {'content-type': 'text/plain'});
res.write('received upload:\n\n');
res.end(util.inspect({fields: fields, files: files}));
});
};
当我去到upload这个页面的时候,点击上传,一直在Loading状态。不知道哪里写错了,好像没有解析post的文件。