-
-
Notifications
You must be signed in to change notification settings - Fork 680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
many properties from Fields return array despite of the FormData didn't append any array #876
Labels
Comments
It is not a bug it is a feature. It is always an array to avoid type error based on different user input. To have a single value use the provided firstValues function: import { IncomingForm, Fields, Files, Options } from "formidable";
import { firstValues } from "formidable/src/helpers/firstValues.js";
import { NextApiRequest } from "next";
export default function parseForm(req: NextApiRequest, options: Partial<Options> = {
multiples: true,
keepExtensions: true,
}) {
const form = new IncomingForm(options);
return new Promise<{fields: Fields, files: Files}>((resolve, reject) => {
form.parse(req, (error, fields, files) => {
if (error) reject(error);
resolve({ fields: firstValues(form, fields), files });
});
});
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Support plan
Context
What are you trying to achieve or the steps to reproduce?
In the browser, I have data is an object whose each property contains only a value as a type string. I use FormData to append those properties. There isn't any duplicate property in the request payload. But when console.log the property in the fields from parseForm function, I got an array with a length equal to 1
What was the result you got?
[ 'CMS/store/test_id' ]
What result did you expect?
'CMS/store/test_id'
The text was updated successfully, but these errors were encountered: