hlj_upyun v0.1.2 Upyun
This is a simple client library for Upyun.
Notes on configuration
All the APIs need a policy
to be passed in. A policy
contains
the configuration information about the connection detail, such
as bucket, operator, and api endpoint.
A typical policy can be:
%Upyun{bucket: "my-bucket", operator: "bob", password: "secret-password", endpoint: :v0}
Examples:
upload
policy = %Upyun{bucket: "my-bucket", operator: "bob", password: "secret-password", endpoint: :v0}
policy |> Upyun.upload("README.md", "/test/README.md")
#=> :ok
Summary
Functions
Delete a remote file
Get the content of remote file
Get information of an object
List entries in a path
Create or update remote file with raw content
Upload a file from local to remote
Upload all files recursively in local directory to remote. Thery are uploaded one by one currently. TODO: upload parallelly
Types
Functions
Delete a remote file.
policy
- upyun configuration objectpath
- remote object path
Returns :ok
if remote file is successfully deleted or does not exist.
Examples
policy |> Upyun.delete("/my/file")
#=> :ok
Get the content of remote file.
policy
- upyun configuration objectpath
- remote object path
Return the raw content string of the file.
Examples
policy |> Upyun.get("/remote/file")
#=> "content of the file..."
Get information of an object.
policy
- upyun configuration objectpath
- remote object path
Examples
# for file:
policy |> Upyun.info("hehe.txt")
#=> {:file, 150, 1448958896}
# for folder:
policy |> Upyun.info("empty_dir")
#=> {:dir, 0, 1448958896}`
List entries in a path.
policy
- upyun configuration objectpath
- remote directory to list
Returns a list of objects.
Examples
policy |> Upyun.list("/")
#=> a list of items, e.g. {:file, "file"} / {:dir, "folder"}
Create or update remote file with raw content.
policy
- upyun configuration objectcontent
- content of the filepath
- remote object path to store the fileopts
- (optional) options for making the HTTP request byHTTPoison
Returns :ok
if successful.
Examples
content = """
<html>
<head>
<title>Hello, world</title>
</head>
<body>Nice to see you.</body>
</html>
"""
policy |> Upyun.put(content, "/remote/path")
#=> :ok
upload(policy, binary, binary, [any]) :: :ok | {:error, any}
Upload a file from local to remote.
policy
- upyun configuration objectlocal_path
- path of the local file to uploadremote_path
- remote object path to store the fileopts
- (optional) options for making the HTTP request byHTTPoison
Returns :ok
if successful.
Examples
policy = %Upyun{bucket: "my-bucket", operator: "bob", password: "secret-password", endpoint: :v0}
policy |> Upyun.upload("/path/to/local/file", "/path/to/remote/object")
#=> :ok
Sending custom headers
By default, elixir-upyun
will automatically send Content-Type
header for you.
You can send custom headers via options. Like:
policy |> Upyun.upload("/local/path", "/remote/path", headers: [
{:"Content-Type", "text/plain"},
{:"X-Foo", "BAR"}
])
upload_dir(policy, binary, binary, [any]) :: [{binary, :ok}]
Upload all files recursively in local directory to remote. Thery are uploaded one by one currently. TODO: upload parallelly
policy
- upyun configuration objectlocal_dir
- local directory to uploadremote_path
- remote object path to store the filesopts
- (optional) options for making the HTTP request byHTTPoison
Returns an list of result object. A result object is a tuple,
with local file name first, and the result (:ok
) followed.
Examples
policy |> upload_dir("/etc", "/remote/etc")
#=> [{"passwd", :ok}, {"fastab", :ok}, ...]