简体   繁体   English

如何通过 express.bodyParser() 和 response.write() 使用 node-formidable

[英]How to use node-formidable with express.bodyParser() and response.write()

I am using node-formidable to upload multipart/formdata.我正在使用 node-formidable 上传 multipart/formdata。 Everything works fine as long as I只要我一切正常

comment the line:注释该行:

//app.use(express.bodyParser());

But the problem is that I want to implement a progress bar on the client side.但问题是我想在客户端实现一个进度条。 For that I am trying to do something like this:为此,我正在尝试做这样的事情:

form.on('progress',function(a,b){
 response.write() //Gives error saying Can't set headers after they have been sent
})

when I use the express bodyParser() res.write() works perfectly.当我使用 express bodyParser() res.write() 时效果很好。

PS:I know this can be done using socket.io, but I dont think that is an elegant solution. PS:我知道这可以使用 socket.io 来完成,但我认为这不是一个优雅的解决方案。

Is there a way to use response.write() and at the same time use formidable?有没有办法在使用 response.write() 的同时使用 formidable?

Thank you.谢谢你。

with body parser you should be able to bind the 'data' event to the req object and then write to the res object with res.write().使用正文解析器,您应该能够将“数据”事件绑定到请求 object,然后使用 res.write() 写入 res object。

I think you're sending response twice for that request.我认为您针对该请求发送了两次响应。 You can't do that simply in node.你不能简单地在节点中做到这一点。 There are few workarounds.解决方法很少。 I'd suggest you read these two answers.我建议你阅读这两个答案。 It might help.它可能会有所帮助。

How to render multiple times on the same response object with ExpressJS? 如何使用 ExpressJS 在同一个响应 object 上多次渲染?

Can I send multiple responses via Node.js to the client? 我可以通过 Node.js 向客户端发送多个响应吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM