Last active
January 4, 2017 02:36
-
-
Save zhongwencool/563e6733d563c11b6a5d12b6db7eac4d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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