httpoison icon indicating copy to clipboard operation
httpoison copied to clipboard

[bug] Multipart file with extra named fields fails to merge properly

Open antonioparisi opened this issue 8 months ago • 0 comments

Hi there,

I was playing around to get the current example working, I kind of managed to, but whenever you need to send params named like the following example:

    {:multipart, [
      {"workspace[c_id]", "..."},
      {"workspace[namespace_uuid]", "..."},
      {"workspace[name]", "workspace name"},
      {"workspace[demo]", "false"},
      {:file, logo_file_path(), {"form-data", [name: "workspace[logo]", filename: Path.basename(logo_file_path())]}, []},
    ]}

what will get sent is the following:

{"workspace"=>{"filename"=>"logo.png", "type"=>"image/png", "name"=>"workspace", "tempfile"=>#<Tempfile:/var/folders/j9/wb2bylys5nqcv4djbdbbvsy40000gn/T/RackMultipart20240528-25837-93ahy6.png>, "head"=>"content-length: 9287\r\ncontent-type: image/png\r\ncontent-disposition: form-data; name=workspace[logo]; filename=logo.png\r\n"}}

now, the expected results ideally would have had also the other attributes under the workspace[] but they got lost apparently.

instead on this other example:

    {:multipart, [
      {"workspace[c_id]", "..."},
      {"workspace[namespace_uuid]", "..."},
      {"workspace[name]", "workspace name"},
      {"workspace[demo]", "false"},
      {:file, logo_file_path(), {"form-data", [name: "logo", filename: Path.basename(logo_file_path())]}, []},
    ]}

what will get sent is the following:

{"workspace"=>{"c_id"=>"...", "namespace_uuid"=>"....", "name"=>"workspace name", "demo"=>"false"}, "logo"=>{"filename"=>"logo.png", "type"=>"image/png", "name"=>"logo", "tempfile"=>#<Tempfile:/var/folders/j9/wb2bylys5nqcv4djbdbbvsy40000gn/T/RackMultipart20240528-25837-x6l46o.png>, "head"=>"content-length: 9287\r\ncontent-type: image/png\r\ncontent-disposition: form-data; name=logo; filename=logo.png\r\n"}}

which is correct. so the issue is only on the first scenario

any hint would be grateful

antonioparisi avatar May 27 '24 23:05 antonioparisi