Skip to content

Instantly share code, notes, and snippets.

@zhongwencool
Last active January 4, 2017 02:36
Show Gist options
  • Save zhongwencool/563e6733d563c11b6a5d12b6db7eac4d to your computer and use it in GitHub Desktop.
Save zhongwencool/563e6733d563c11b6a5d12b6db7eac4d to your computer and use it in GitHub Desktop.
defmodule SendFileClient do
use Maxwell.Builder, ~w(post)a
middleware Maxwell.Middleware.BaseUrl, "http://httpbin.org"
middleware Maxwell.Middleware.Opts, [connect_timeout: 10000, recv_timeout: 20000]
adapter Maxwell.Adapter.Hackney
@doc """
Post whole file once
###Example
Client.post_file_once("./mix.exs")
"""
def post_file_once(filepath) do
new
|> put_path("/post")
|> put_req_body({:file, filepath})
|> post!
|> get_resp_body()
end
@doc """
Post whole file by chunked
###Example
Client.post_file_chunked("./mix.exs")
"""
def post_file_chunked(filepath) do
new
|> put_path("/post")
|> put_req_header("transfer_encoding", "chunked")
|> put_req_body({:file, filepath})
|> post!
|> get_resp_body()
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment