node上传模块busboy
##基本用法
var Busboy = require('busboy');
exports.upload = function(req, res){
busboy.on('file', function (fieldname, file, filename, encoding, mimetype) {
var saveTo = path.join(__dirname, '../public/uploads', path.basename(filename));
photo = saveTo;
file.pipe(fs.createWriteStream(saveTo));
});
busboy.on('finish', function () {
// 业务逻辑代码
res.redirect('/');
});
});
return req.pipe(busboy);
}
\n```
##表单有其他非文件字段
```js\n
busboy.on('field', function (fieldname, val) {
if (fieldname == 'school')
var school = validator.trim(inspect(val));
if (fieldname == 'hobby')
var hobby = validator.trim(inspect(val));
});
\n```
1 回复
一些简单的使用,