node-formidable / formidable

The most used, flexible, fast and streaming parser for multipart form data. Supports uploading to serverless environments, AWS S3, Azure, GCP or the filesystem. Used in production.
MIT License
7k stars 680 forks source link

Formdata is string, but parse resulting is array? #950

Closed Robert-Du0001 closed 11 months ago

Robert-Du0001 commented 11 months ago

Support plan

Context

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' }
GrosSacASac commented 11 months ago

Not a bug. Mentioned in changelog Use helper function firstValues to get desired result

kugruw commented 5 months ago

How do I import the helper function firstValues in typescript? @GrosSacASac

Hyodori04 commented 4 months ago

I want to use typescript too