'POST multiple array params with multiple input file type

I'm confused to solve a problem. I have a form to POST

<input multiple="multiple" name="dog[gallery_pictures_attributes][][file]" type="file">
<input name="dog[gallery_pictures_attributes][][crop]">
<input name="dog[gallery_pictures_attributes][][resize]">
<input name="dog[gallery_pictures_attributes][][crop]">
<input name="dog[gallery_pictures_attributes][][resize]">
<input name="dog[gallery_pictures_attributes][][crop]">
<input name="dog[gallery_pictures_attributes][][resize]">

I need to receive an array of params like

"gallery_pictures_attributes"=>[
  {"file"=>"ryJfcmF", "crop"=>"1638x1053+205+156", "resize"=>"1400x900"},
  {"file"=>"ddfvdfv", "crop"=>"1638x1053+205+156", "resize"=>"1400x900"},
  {"file"=>"eyfvfmF", "crop"=>"1638x1053+205+157", "resize"=>"1400x900"}, 
]}

But I've got

"gallery_pictures_attributes"=>[
  {"file"=>"ryJfcmF"},
  {"file"=>"ddfvdfv"},
  {"file"=>"eyfvfmF", "crop"=>"1638x1053+205+157", "resize"=>"1400x900"}, 
  {"crop"=>"1638x1053+205+156", "resize"=>"1400x900"},
  {"crop"=>"1638x1053+205+156", "resize"=>"1400x900"}
]}

Please advise



Solution 1:[1]

Got it! Params order is matter! Issue is in only one [file] input, that's why the last file in the input has [crop] and [resize] params. Problem solved generating file inputs for every [crop] and [resize] params:

<input type="file" name="dog[gallery_pictures_attributes][][file]">. 
<input name="dog[gallery_pictures_attributes][][crop]">
<input name="dog[gallery_pictures_attributes][][resize]">

<input type="file" name="dog[gallery_pictures_attributes][][file]">
<input name="dog[gallery_pictures_attributes][][crop]">
<input name="dog[gallery_pictures_attributes][][resize]">

<input type="file" name="dog[gallery_pictures_attributes][][file]">
<input name="dog[gallery_pictures_attributes][][crop]">
<input name="dog[gallery_pictures_attributes][][resize]">

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Artem Aminov