是要在 app.js
里添加:
app.use(bodyParser({ keepExtensions: true, uploadDir: './public/images' })); ?
我表单的 file
的名字为 file1
,在接收请求里这样子写
router.post('/', function(req, res){
console.log(req.files.file1);
});
会报:
TypeError: Cannot read property 'file1' of undefined
请问如何实现个简单上传?谢谢!
13 回复
@youxiachai 我遇到个错误,我代码是这样子的:
router.post('/’, function(req, res){
var form = new multiparty.Form();
req.form.on('part’, function(part){
// transfer to s3 etc
console.log('upload %s %s’, part.name, part.filename);
var out = fs.createWriteStream(‘/tmp/’ + part.filename);
part.pipe(out);
});
req.form.on('close’, function(){ res.end(‘uploaded!’); }); }); 我已经安装了组建并var multiparty = require(‘multiparty’);但是总是报这个错误:Cannot call method ‘on’ of undefined
formidable +1 https://www.npmjs.org/package/formidable coffeescript 示例:
form = new formidable.IncomingForm()
form.parse req, (err, fields, files)->
console.log files
console.log fields