0

那么使用 bodyParser 进行文件上传的优缺点是什么?

我的意思是使用 bodyParser 我将文件放入 /var/ 目录,然后在上传后将其移动到我的目录,它使我可以轻松访问名称文件和其他信息,但是没有 bodyParser 我可以对文件执行一次操作“完成”事件被触发..

有没有办法知道何时使用 bodyParser,何时不使用文件?

4

1 回答 1

0

如果您正在使用express,您可以在bodyParser.

像这样的东西:

app.use( function( req, res, next ) {
    ... code here runs before bodyparser
    next();
    ... code here runs on the way back (only when there is no error)
});
app.use( express.bodyParser() );
app.use( function( req, res, next ) {
    ... code here runs after bodyparser, before route
    next();
    ... code here runs on the way back (only when there is no error)
});

在这种情况下,您可以同时使用两者。

最好的问候罗伯特

于 2013-05-23T16:11:03.247 回答