Formdata is string, but parse resulting is array?
Robert-Du0001 opened this issue · comments
Support plan
- Which support plan is this issue covered by? (Community, Sponsor, Enterprise): community
- Currently blocking your project/work? (yes/no): no
- Affecting a production system? (yes/no): no
Context
- Node.js version: v18.16.1
- Formidable exact version: 3.5.0
- Environment (node, browser, native, OS): node
- Used with (popular names of modules):
What are you trying to achieve or the steps to reproduce?
Parsing formdata, I expect the resulting is string instead of array.
Here's the formdata:
--------------------------1a86a97a8a69a7c1
Content-Disposition: form-data; name="operate"
zip
--------------------------1a86a97a8a69a7c1
Content-Disposition: form-data; name="sour"
aaa
--------------------------1a86a97a8a69a7c1
Content-Disposition: form-data; name="bbb"
ccc
--------------------------1a86a97a8a69a7c1--
And here's the code that's processing it:
const formidable = require('formidable');
const form = new formidable.IncomingForm();
form.parse(req, (err, fields, files) => {
console.log('Fields:', fields);
});
What was the result you got?
The resulting looks like this:
Fields: { operate: [ 'zip' ], sour: [ 'aaa' ], bbb: [ 'ccc' ] }
What result did you expect?
I expected the resulting looks like this:
Fields: { operate: 'zip' , sour: 'aaa' , bbb: 'ccc' }
Not a bug.
Mentioned in changelog
Use helper function firstValues to get desired result
How do I import the helper function firstValues in typescript? @GrosSacASac
I want to use typescript too