现在看的是node.js实战这本书,书上说bodyParser()更具体的说是multipart()中间件他会给你一个req.files对象,代表上传的对象。
我照着书上的代码敲的,结果总是undefined,Cannot read property ‘photo’ of undefined。搜了下body-parser,看到上面写着
This does not handle multipart bodies, due to their complex and typically large nature.
For multipart bodies, you may be interested in the following modules:
意思是不是body-parser模块不再支持multipart。
下面app.js有代码:
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.set('photos',__dirname+'/public/photos');
app.get('/upload',photos.form);
app.post('/upload',photos.submit(app.get('photos')));
photo.js里有代码:
茅侃侃
相关分类