Expressjs bodyParser和连接forms

我用连接forms上传图像。 但是,如果我使用bodyParser()它是行不通的。 而相反,如果我不使用bodyParser,我不能上传文件?

我如何让他们一起玩? 这是我的configuration:

 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 1.8.x开始不推荐使用)。

只需要在你的路由中使用req.files来获取上传的文件,其余的是Express。 看看这个post:

http://tjholowaychuk.com/post/12943975936/connect-1-8-0-multipart-support