Skip to content

Instantly share code, notes, and snippets.

@zhongwencool
Created January 4, 2017 02:45
Show Gist options
  • Save zhongwencool/9e0b895df041a7b721e08ceb98343d4a to your computer and use it in GitHub Desktop.
Save zhongwencool/9e0b895df041a7b721e08ceb98343d4a to your computer and use it in GitHub Desktop.
defmodule SendMultipartClient do
use Maxwell.Builder, ~w(post)a
middleware Maxwell.Middleware.BaseUrl, "http://httpbin.org"
middleware Maxwell.Middleware.Opts, [connect_timeout: 10000, recv_timeout: 20000]
middleware Maxwell.Middleware.DecodeJson
adapter Maxwell.Adapter.Hackney
@doc """
Post multipart form
###Example
SendMultipartClient.post_multipart_form({:multipart, [{:file, "./mix.exs"}]})
"""
def post_multipart_form(multipart) do
new
|> put_path("/post")
|> put_req_body(multipart)
|> post!
|> get_resp_body(["files", "file"])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment