Closed skerit closed 3 years ago
Thank you for raising this issue! We will try and get back to you as soon as possible. Please make sure you format it properly, followed our code of conduct and have given us as much context as possible. /cc @tunnckoCore @GrosSacASac
Yes. v1.x is known with a lot of this bug. The canary tag handles them, see the changelog - a ton is closed, fixed and merged. That's the recommended path anyway, in the same time helps for polishing the v2 before release.
Try and report back please :)
Hey. @tunnckoCore . Thanks for letting us know. Can't wait for v2. Keep up the good work.
@tunnckoCore I just tried using formidable@canary. Sending files using multipart/form-data
doesn't turn properties correctly ending with []
or ending with [0]
[1]
etc in an array. It keeps the square brackets 😢
The following form data:
is translated to this:
I've just tried using formidable@canary
and it works!
@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
I think the media[]
key shouldn't have the []
string at the end
@IonelLupu Can you show the code you use to submit the form ?
@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
Im using canary tag when installing and this problem still exists for me.
Using as:
import { IncomingForm } from 'formidable';
....
const form = new IncomingForm({
// @ts-ignore Formidable@canary
maxFields: 50,
multiples: true,
});
form.parse(req, function (err, fields, files) {
if (err) {
return next(err);
}
console.log(files)
I think it doesn't matter if the form name has []. What counts is if the client sends multiple files or multiples inputs with the same name are sent.
Im using canary tag when installing and this problem still exists for me.
Using as:
import { IncomingForm } from 'formidable'; .... const form = new IncomingForm({ // @ts-ignore Formidable@canary maxFields: 50, multiples: true, }); form.parse(req, function (err, fields, files) { if (err) { return next(err); } console.log(files)
You don't need the [] for files, only for fields, just send multiple files with the same key and you should get an array.
Support plan
Context
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):
And here's the code that's processing it:
What was the result you got?
The resulting
form_fields
object looks like this:What result did you expect?
Instead of a
categories[]
property, I expected acategories
property with an array of all the submitted values.