multer
multer copied to clipboard
having a custom middleware that adds a req.on('data', (chunk)->{ //manipulate some data from chunk }), doesn't allow multer to generate the file filed on req.
Hi, I have a custom global middleware that adds a listener on req.on(data), this is part of our glocal HTTP logging middleware. However, when this middleware is on, any file uploaded on a path with multer enabled doesn't generate the file field as expected. I've spent a lot of time debugging this and found this. I have no clue as to why.
It works as soon as I comment the on data listener.
This is because attaching attaching a data listener will make data start flowing, and since this is before the stream gets passed to Multer my guess is that the first packet or two gets emitted only to your logging middleware.
ref: https://nodejs.org/api/stream.html#event-data
Potentially you could pause the stream before adding your listener.
Since this is outside of Multer I'll close the issue, I would recommend Stack Overflow to solve the general question of "how to listen to all data on a stream without affecting other consumers" 👍