无法使用Multer / Express从多部分表单返回POST数据

问题描述 投票:0回答:1

使用multer with expressjs我在Git Bash shell中从多部分表单发布数据时似乎无法获得console.log()响应。注意,我只返回文本,所以我确实在post请求中应用了“upload.none()”。

不确定我的register.jade文件或users.js文件本身是否有问题...

multer是否需要在app.js中使用“app.use(....)语句?我在文档中没有看到任何内容

我的表格(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.m-b-20(type='submit', name='submit' value='Register')
                .register-link
                  p
                    | Already have account?
                    br
                    a(href='/users/login') Sign In

这是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;
node.js express git-bash multer
1个回答
0
投票

如果有人偶然发现这个问题,我终于找到了我的错误!!

该死的玉/帕格格式。这就是我所信赖的在线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

.form-group需要一个额外的“tab”或缩进,以便全部工作。在这里,我正在追逐快速和闷热的错误3天

© www.soinside.com 2019 - 2024. All rights reserved.