question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Properties ending with `[]` are not turned into an array, even with the `multiples: true` option

See original GitHub issue

Support plan

  • which support plan is this issue covered by? (e.g. Community, Sponsor, or Enterprise): community
  • is this issue currently blocking your project? (yes/no): no
  • is this issue affecting a production system? (yes/no): yes

Context

  • node version: 12.16.2
  • module (formidable) version: 1.2.2
  • environment (e.g. node, browser, native, OS): node
  • used with (i.e. popular names of modules):
  • any other relevant information:

What are you trying to achieve or the steps to reproduce?

Parsing formdata with multiples: true does not actually result in an array of values.

Here’s the formdata (minus the file):

-----------------------------40560332322476987903819948371
Content-Disposition: form-data; name="number"

2019-482
-----------------------------40560332322476987903819948371
Content-Disposition: form-data; name="followed_workshop"

none_ext
-----------------------------40560332322476987903819948371
Content-Disposition: form-data; name="categories[]"

architecture
-----------------------------40560332322476987903819948371
Content-Disposition: form-data; name="categories[]"

product

And here’s the code that’s processing it:

let form = new formidable.IncomingForm({multiples: true});

form.hash = 'md5';

form.parse(req, function parsedMultipart(err, form_fields, form_files) {
	console.log(form_fields);
});

What was the result you got?

The resulting form_fields object looks like this:

{
    "categories[]": "product",
    "followed_workshop": "none_ext",
    "number": "2019-482"
}

What result did you expect?

Instead of a categories[] property, I expected a categories property with an array of all the submitted values.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
IonelLupucommented, Dec 13, 2020

@GrosSacASac I retested the code and it seems it’s now working as expected. I don’t know what was the issue before. I guess we can close this now

1reaction
IonelLupucommented, Nov 15, 2020

@nawawishkid-old I just tried formidable@canary as well, right now, and I get the same thing I said in the previous comment:

form.parse(incomingMessage, (error, content, formidableFiles) => {
  // formidableFiles is an object with the keys containing `[]` and the end for multiple media files, even if the value is an array
})

As show in the image below image

I think the media[] key shouldn’t have the [] string at the end

Read more comments on GitHub >

github_iconTop Results From Across the Web

5. Working with Arrays and Loops - JavaScript Cookbook [Book]
The array begins at zero, and the array property length is used to set the loop end. Sometimes, though, you don’t want to...
Read more >
Arrays - The Modern JavaScript Tutorial
There exists a special data structure named Array , to store ordered collections. Declaration. There are two syntaxes for creating an empty ...
Read more >
Data Structures: Objects and Arrays - Eloquent JavaScript
When you compare objects with JavaScript's == operator, it compares by identity: it will produce true only if both objects are precisely the...
Read more >
Chapter 7: Arrays - cs.utsa.edu
Write a program that declares a double array of length 4, prints the values, assigns a value to each element, and prints the...
Read more >
JavaScript Arrays - tips, tricks and examples - CodinGame
The items in the array are nothing more than properties of that objects. You can use any name as property for an objects,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found