Properties ending with `[]` are not turned into an array, even with the `multiples: true` option
See original GitHub issueSupport 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:
- Created 3 years ago
- Reactions:4
- Comments:11 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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
@nawawishkid-old I just tried
formidable@canary
as well, right now, and I get the same thing I said in the previous comment:As show in the image below
I think the
media[]
key shouldn’t have the[]
string at the end