[英]Unable to return POST data from multipart form using Multer / Express
Using multer with expressjs I can't seem to get a console.log() response in my Git Bash shell when posting data from a multipart form. 使用multer with expressjs我在Git Bash shell中从多部分表单发布数据时似乎无法获得console.log()响应。 Note, I'm only returning text so I do have the "upload.none()" applied in the post request.
注意,我只返回文本,所以我确实在post请求中应用了“upload.none()”。
Not sure if I have a problem within my register.jade file or in the users.js file itself... 不确定我的register.jade文件或users.js文件本身是否有问题...
Does multer require an "app.use(....) statement in app.js? I didn't see anything in the documentation multer是否需要在app.js中使用“app.use(....)语句?我在文档中没有看到任何内容
My Form (register.jade): 我的表格(register.jade):
body.animsition .page-wrapper .page-content--bge5 .container .login-wrap .login-content .login-logo a(href='#') img(src='/images/QTI-Logo.jpg', alt='') .login-form form(action='/users/register', method='post', enctype='multipart/form-data') .form-group label Full Name input.au-input.au-input--full(type='text', name='name', placeholder='Your Name') .form-group label Username input.au-input.au-input--full(type='text', name='username', placeholder='Desired Username') .form-group label Email Address input.au-input.au-input--full(type='email', name='email', placeholder='Email') .form-group label Password input.au-input.au-input--full(type='password', name='password', placeholder='Password') .form-group label Confirm Password input.au-input.au-input--full(type='password', name='password2', placeholder='Confirm Password') input.au-btn.au-btn--block.au-btn--green.mb-20(type='submit', name='submit' value='Register') .register-link p | Already have account? br a(href='/users/login') Sign In
Here's the users.js file: 这是users.js文件:
var express = require('express'); var router = express.Router(); var multer = require('multer'); var upload = multer(); /* GET users listing. */ router.get('/', function(req, res, next) { res.send('respond with a resource'); }); router.get('/register', function(req, res, next) { res.render('register', {title: 'Register'}); }); router.get('/login', function(req, res, next) { res.render('login', {title: 'Login'}); }); router.post('/register', upload.none(), function(req, res, next) { console.log(req.body.name); }); module.exports = router;
In case anyone stumbles upon this issue as well, I finally found my error!! 如果有人偶然发现这个问题,我终于找到了我的错误!!
Damn Jade/Pug formatting. 该死的玉/帕格格式。 That's what I get for trusting an online HTML >> Jade convertor I guess.
这就是我所信赖的在线HTML >> Jade转换器我猜。
.login-form
form(action='/users/register', method='post', enctype='multipart/form-data')
.form-group
label Full Name
input.au-input.au-input--full(type='text', name='name', placeholder='Your Name')
.form-group
label Username
input.au-input.au-input--full(type='text', name='username', placeholder='Desired Username')
.form-group
label Email Address
input.au-input.au-input--full(type='email', name='email', placeholder='Email')
.form-group
label Password
input.au-input.au-input--full(type='password', name='password', placeholder='Password')
.form-group
label Confirm Password
input.au-input.au-input--full(type='password', name='password2', placeholder='Confirm Password')
input.au-btn.au-btn--block.au-btn--green.m-b-20(type='submit', name='submit' value='Register')
.register-link
p
| Already have account?
br
a(href='/users/login') Sign In
The .form-group needed one extra "tab" or indent for this all to work. .form-group需要一个额外的“tab”或缩进,以便全部工作。 And here I was chasing down express and multer errors for 3 days
在这里,我正在追逐快速和闷热的错误3天
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.