无法使用Multer / Express

时间:2019-03-31 13:56:20

标签: node.js express git-bash multer

在ExpressJS中使用multer时,从多部分表单中发布数据时,我的Git Bash shell中似乎无法获得console.log()响应。请注意,我只返回文本,因此在发帖请求中确实应用了“ 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;

1 个答案:

答案 0 :(得分: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组需要一个额外的“制表符”或缩进才能使所有这些起作用。在这里,我追踪了3天的快递和multer错误