formidable icon indicating copy to clipboard operation
formidable copied to clipboard

Invalid request fields parsing with multiples option

Open kkaminski-github opened this issue 5 years ago • 5 comments

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): yes
  • is this issue affecting a production system? (yes/no): yes

Context

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

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

When setup formidable body parser with option multiples:true I expected thet I can send array in form that sould be correctly represented in req.fields.

image

app.use(formidable({multiples:true}));

What was the result you got?

It is not parsed correctly: image

What result did you expect?

Array should be available in req.fields { advertiserId: '1122', videoLength: '7', videoWidth: '970', videoHeight: '250', videos:[ {test: '7'} ] }

From the docs:

options.multiples {boolean} - default false; when you call the .parse method, the files argument (of the callback) will contain arrays of files for inputs which submit multiple files using the HTML5 multiple attribute. Also, the fields argument will contain arrays of values for fields that have names ending with '[]'. 

Maybe I should name fields differently?

kkaminski-github avatar Sep 09 '21 21:09 kkaminski-github

videos:[ {test: '7'} ] is an array of object, use JSON if you want that.

Your field is not ending with [] and you are not sending multiple entries with that same name

GrosSacASac avatar Sep 09 '21 21:09 GrosSacASac

Thank you for looking into my issue @GrosSacASac

image image

I need form data as I also transfer files in that request

kkaminski-github avatar Sep 09 '21 21:09 kkaminski-github

Try again with version 3

GrosSacASac avatar Sep 09 '21 21:09 GrosSacASac

Is it available on npm? https://www.npmjs.com/package/formidable

kkaminski-github avatar Sep 09 '21 22:09 kkaminski-github

https://www.npmjs.com/package/@grossacasacs/formidable

GrosSacASac avatar Sep 09 '21 22:09 GrosSacASac