現(xiàn)在看的是node.js實戰(zhàn)這本書,書上說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里有代碼:
node.js如何上傳圖片
暮色呼如
2019-02-04 14:25:42