在节点应用程序中未定义req.file

时间:2016-05-17 18:25:50

标签: javascript node.js express multer

我检查了multer doc并在stackoverflow中搜索了4小时,但没有运气, 这是我的代码:

form(role='form' method='post' action='/add-post/new' enctype="multipart/form-data")
                .form-group
                    label(for='title') Title:
                    input#title.form-control(type='input' name='title')
                .form-group
                    label Product Image:
                    input(type='file' name='image')
                button.btn.btn-default(type='submit') Save 

JS

var express = require('express');
var router = express.Router();
var fs = require('fs');
var bodyParser = require('body-parser');
var multer = require('multer');

var Post = require('../models/post')

var upload = multer({ dest: './uploads/' });


/* GET home page. */
router.get('/', function(req, res, next) {
    res.render('new-post', { title: 'New Post' });
});
router.post('/new',upload.single('image'), function(req, res) {
    console.log("das", req.body, req.file)
})  

发送表单后,我从req.file获得了undefine

有什么建议吗?感谢

0 个答案:

没有答案