mateusppereira
mateusppereira

Reputation: 960

Elixir HttpPoison not working to send multipart/form-data requests

I have a very simple request to make but it looks like HttpPoison isn't able to resolve this.

The request has attachments, so i'm using multipart/form-data content type.

When I send just the file, the request works fine, but I need to add some other props to my request and that's where the issue comes.

My request:

HTTPoison.post(
  "path.com/api/anything",
  {:multipart, [
    {
      :file,
      "/path/file.xlsx",
      {"form-data", [name: "file", filename: "file.xlsx"]}, []
    },
    {"taskName", "#{task.name}"},
    {"taskLink", "#{task.link}"}
  ]},
)

I receive the file without problems but the taskName and taskLink never reach the server.

( I tried with postman and had no problems )


Some issues related to this:

https://elixirforum.com/t/httpoison-post-multipart-with-more-form-than-the-file/4222/4 https://github.com/edgurgel/httpoison/issues/237

Upvotes: 3

Views: 1160

Answers (1)

Don Pflaster
Don Pflaster

Reputation: 1040

We have a working example of the multipart list that we use to send zip files along with other attributes. Something equivalent to this might work for you.

[
  {"id", to_string(order_id)},
  {"file_size", to_string(file_size)},
  {"attachment", file, {"form-data", [name: "file", filename: filename]},
    [{"Content-Type", "application/zip"}]
  }
]

Upvotes: 2

Related Questions