Reputation: 7385
I need to send a (multipart) HTTP request which contains a file which is named. This seems to be harder to achieve than I imagined... I've tried to figure out a way to do it with HTTPoison, but I can't get it to use a name other than "file". I've tried using Hackney directly, but there doesn't appear to be an option, and there definitely isn't a test on either of these which shows this functionality. I've also had a look at ibrowse and HTTPotion but can't find anything which seems useful (my Erlang is very limited, mind you). Here is an example of what I want to do, with the Ruby library Curb (note the Curl::PostField.file takes a name and a file path).
Is this such a strange thing to do? Or am I missing something obvious here... Any suggestion is greatly appreciated.
Thanks!
Upvotes: 3
Views: 2697
Reputation: 2067
I managed to get it working with
HTTPoison.post!(url, {:multipart, [{"name", "value"}, {:file, path_to_file}]})
with some help from this Github issue
Upvotes: 1
Reputation: 7385
In case anyone in the future encounters this problem, here's the solution:
HTTPoison.start
request = HTTPoison.post!(url, {:multipart, [{:file, "path/to/file", { ["form-data"], [name: "\"photo\"", filename: "\"/path/to/file\""]},[]}]}, headers, options)
Note the extra escaped quotes.
Upvotes: 15