geo*_*per 5 javascript node.js express
我用连接表单上传图片.但如果我使用它,它就不起作用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());
});
Run Code Online (Sandbox Code Playgroud)
如果您使用的是最新的Express,则不需要包含connect-form(自Connect 1.8.x以来不推荐使用).
只需在路由中使用req.files即可获取上传的文件,Express会完成剩下的工作.看看这篇文章:
http://tjholowaychuk.com/post/12943975936/connect-1-8-0-multipart-support
| 归档时间: |
|
| 查看次数: |
4907 次 |
| 最近记录: |