我用连接表单上传图片.但是如果我使用bodyParser()它就不起作用.
反过来说,如果我不使用bodyParser,我无法上传文件?
我如何让他们一起玩?这是我的配置:
app.configure(function() {
app.register('.html', require('ejs'));
app.set('views', __dirname + '/../views');
app.set('view engine', 'html');
app.use(gzippo.staticGzip(__dirname + '/../public'),{ maxAge: 86400000 });
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(form({
keepExtensions: true,
uploadDir: __dirname + '/../tmp'
}));
app.use(express.cookieParser());
app.use(express.session({
secret: 'test',
cookie: { secure: true },
store: new MySQLSessionStore(client.database, client.user, client.password)
}));
app.use(expressValidator);
app.use(app.router);
app.use(express.csrf());
});
解决方法:
如果您使用的是最新的Express,则不需要包含connect-form(自Connect 1.8.x以来不推荐使用).
只需在路由中使用req.files即可获取上传的文件,Express会完成剩下的工作.看看这篇文章:
http://tjholowaychuk.com/post/12943975936/connect-1-8-0-multipart-support
原文地址:https://codeday.me/bug/20190521/1146973.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。