In node.js why does passport session stop formidable from triggering 'file' events?

落爺英雄遲暮 提交于 2019-12-18 11:58:39

问题


In my app I am only using

app.use(express.json());
app.use(express.urlencoded());

and not

app.use(express.bodyParser());

so that I can manually parse file uploads. It seems that this line

app.use(passport.session());

stops formidable from triggering file events:

form.on('file', function(name, file) {
  //never called
});

How can I use passport session and not clash with formidable file event?


回答1:


Looks like they've added a way to fix this. Using app.use(passport.session({pauseStream: true})); instead will prevent async deserializations from breaking some middleware.

Source: https://github.com/jaredhanson/passport/pull/106




回答2:


The passport.session() method calls your passport.deserializeUser(), which itself usually makes a database call to fetch the user. This database call delays the execution of code that starts listening to the incoming data. That is, the data arrives while nobody is listening for it.



来源:https://stackoverflow.com/questions/14479343/in-node-js-why-does-passport-session-stop-formidable-from-triggering-file-even

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!