Closed szarkowicz closed 2 years ago
Doing some more digging - this only breaks / hangs when I am sending JSON data - example sending JSON through POSTMAN. Mutlipart form still works
what happens if you remove app.use(express.json()); // <-- breaks formidable this line, formidable should already handle json
Hi GrosSacASac,
That is correct that it does, but I need to be be able to pass req and have req.body populated to our logging API. So when I enable app.use(express.json()); - I can just pass the request as middleware. Once I turn this on Formidable no longer works with submitting JSON data.
use formidable as a middleware, in the middleware use req.body = fields
We are handling json by deafult too. Disable the json plugin (see "enabledPlugins" docs) and probably the urlencodeded one, and then you should be able to use express.json() without problems.
for us: @GrosSacASac we probably should export a proper middleware which would be recommended. i always thought for that.
Use this package: express-formidable-v2 Check this []https://github.com/Abderrahman-byte/express-formidable-v2 out, It is a fork of "express-formidable" package
Now you have req.fields and req.body coexisting
Context
What are you trying to achieve or the steps to reproduce?
When I add app.use(express.json()); to my server.js file this line causes formidable to break / hang with no error. As soon as I comment out that line, formidable works as expected.
I know that app.use(express.json()) gives access to req.body but not sure why this is breaking formidable.
When I debug the formidable.js file I noticed that on('data') is never called when express.json() is used.
I googled a bunch of times to see if there was any similar issues but I could not find anyone that was was having similar issue.
Thanks in advance for any help or suggestions.