-
-
Notifications
You must be signed in to change notification settings - Fork 689
Convert 'firstValues' helper into an option for Formidable constructor. #973
Copy link
Copy link
Open
Labels
Area: APIsThings related to external and internal APIsThings related to external and internal APIsStatus: AcceptedIt's clear what the subject of the issue is about, and what the resolution should be.It's clear what the subject of the issue is about, and what the resolution should be.Status: AvailableNo one has claimed for resolving this issue. Generally applied to bugs and enhancement issues.No one has claimed for resolving this issue. Generally applied to bugs and enhancement issues.
Metadata
Metadata
Assignees
Labels
Area: APIsThings related to external and internal APIsThings related to external and internal APIsStatus: AcceptedIt's clear what the subject of the issue is about, and what the resolution should be.It's clear what the subject of the issue is about, and what the resolution should be.Status: AvailableNo one has claimed for resolving this issue. Generally applied to bugs and enhancement issues.No one has claimed for resolving this issue. Generally applied to bugs and enhancement issues.
Support plan
Enterprise): Community
Context
What problem are you trying to solve?
Hello, Formidable community:
Today I started developing a Node.js server on Express.js to handle Next.js + TypeScript requests, and I came across an issue when trying to parse the body from the request that is sent as FormData. After some research I chose Formidable to parse the FormData. I managed to parse the data, and then I noticed the fields were retrieved and sent back as arrays in the response (for example,
email: ['user@mail.com']), so I went back on the documentation and I found the 'firstValues' helper.Everything works fine now - the values are sent as
key: valueinstead ofkey: [value], but I find it difficult to deal with such a common issue a lot of developers are probably facing. Since Next.js + TypeScript almost forces to pass the body as FormData even for text inputs, and Node.js requires an external parser such as Formidable, I am afraid a lot of developers are dealing with this issue over and over again.My suggestion is to convert the 'firstValues' helper into another option that can be passed to the Formidable constructor, in the same way as
{ maxFiles: 1 },{ multiples: true }, and the rest of options withinDEFAULT_OPTIONSconstant. That would make it a lot easier to deal with this issue, asconst { firstValues } = require("formidable/src/helpers/firstValues.js")would no longer be required and it would be replaced byconst form = formidable({ firstValues: true }).Note: I am new to Formidable and barely have any experience with TypeScript, so if there is currently a way of doing this I would be so thankful if you explain it.
Thank you all for your help.
Do you have a new or modified API suggestion to solve the problem?
I don't.