html代码
<form method="post" class="upload" action="/jsreview/upload" enctype='multipart/form-data'> <input type="file" name='jsfile' accept="text/javascript,application/javascript"/> <input type="submit" /> </form>
js代码:
var multer = require('multer'); var upload = multer({dest:__dirname+'/files/'}); var app = express(); app.use(express.static('./')); app.get('/jsreview',function(req,rsp){ rsp.sendfile('./index.html'); }); app.post('/jsreview/upload',upload.single('jsfile'),function(req,rsp){ console.log(req.body,req.files); rsp.send('success'); }); app.listen(12345);
选择好文件并点击提交按钮后,console.log输出的是{}与undefined。我抓了下包显示
Request Payload: ------WebKitFormBoundary3bQrxuFKQA21XmiJ Content-Disposition: form-data; name="jsfile"; filename="新建文本文档.js" Content-Type: application/javascript ------WebKitFormBoundary3bQrxuFKQA21XmiJ--
大神们帮我看看问题出在哪。
撒科打诨
相关分类