我用multer无法上传
index.jade
block content
h1= title
p Welcome to #{title}
form(method="POST",action='/avatar',entype='multipart/form-data').form-horizontal
.form-group
label.col-md-2.control-label(for='upload') 上传
.col-md-10
input.form-control(type='file',id='upload',name='avatar')
button.btn.btn-primary.control-label(type="submit") 上传
app.js
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var port = process.env.PORT || 3000;
var multer = require('multer');
var upload = multer({dest:'./uploads/'});
var fs = require('fs');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.listen(port);
app.get('/',function (req,res,next) {
res.render('index',{title:'上传'});
});
app.post('/avatar',upload.single('avatar'),function(req, res) {
console.log(upload.single('avatar'));
console.log(req.file);
res.status(200).json({ file: req.file});
});
然后运行后的req.file是undefined
并且uploads文件夹下没有上传的文件
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Lose 'c' in enctype ,不好意思
不是files吗