webdavex v0.1.0 Webdavex.Client View Source
hackney based WebDAV client.
It is recommended to use Webdavex
module to define your own client
instead of using Webdavex.Client
directly.
With
defmodule MyClient
use Webdavex, base_url: "http://webdav.host"
end
you can write
MyClient.get("image.png")
instead of
Webdavex.Config.new(base_url: "http://webdav.host") |> Webdavex.Client.get()
Link to this section Summary
Functions
Copies a file on webdav server. Refer to move/4
for details
Deletes file or directory on webdav server
Gets a file from webdav server
Creates a folder on wedav server
Creates nested folders for given path or file
Moves a file on webdav server
Uploads local file or binary content to webdav server
Link to this section Functions
copy( Webdavex.Config.t(), source :: String.t(), dest :: String.t(), overwrite :: boolean() ) :: {:ok, :copied} | {:error, atom()}
Copies a file on webdav server. Refer to move/4
for details.
Examples
MyClient.copy("image.png", "image_copy.png")
{:ok, :copied}
delete(Webdavex.Config.t(), path :: String.t()) :: {:ok, :deleted} | {:error, atom()}
Deletes file or directory on webdav server.
Examples
MyClient.delete("file.png")
{:ok, :deleted}
get(Webdavex.Config.t(), path :: String.t()) :: {:ok, binary()} | {:error, atom()}
Gets a file from webdav server.
Examples
MyClient.get("foo.png")
{:ok, <<binary content>>}
mkcol(Webdavex.Config.t(), path :: String.t()) :: {:ok, :created} | {:error, atom()}
Creates a folder on wedav server.
Note that webdav does not allow to create nested folders (HTTP 409 will be returned).
Use mkcol_recursive/2
to create nested directory structure.
Examples
MyClient.mkcol("foo")
{:ok, :created}
mkcol_recursive(Webdavex.Config.t(), path :: String.t()) :: {:ok, String.t()} | {:error, atom()}
Creates nested folders for given path or file.
Performs sequential mkcol/2
calls to populate nested structure.
Examples
Create structure for a file.
MyClient.mkcol_recursive("foo/bar/baz/file.png")
{:ok, :created}
“foo”, “foo/bar” and “foo/bar/baz” folders will be created.
Create structure for a folder.
MyClient.mkcol_recursive("foo/bar/")
{:ok, :created}
Note that trailing slash is required for directory paths.
move( Webdavex.Config.t(), source :: String.t(), dest :: String.t(), overwrite :: boolean() ) :: {:ok, :moved} | {:error, atom()}
Moves a file on webdav server.
If overwrite option (3rd argument) is set to false (true by default) will return {:error, :http_412} in case of destination file already exists.
Examples
MyClient.move("imag.png", "image.png")
{:ok, :moved}
put( Webdavex.Config.t(), path :: String.t(), {:file, String.t()} | {:binary, binary()} ) :: {:ok, :created} | {:ok, :updated} | {:error, atom()}
Uploads local file or binary content to webdav server.
Note that webdav specification only allows to create files in already existing folders
which means thah you must call mkcol/2
or mkcol_recursive/2
manually.
Examples
Upload local file
MyClient.put("image.png", {:file, "/home/username/img.png"})
{:ok, :created}
Upload custom binary content
MyClient.put("file.ext", {:binary, <<42, 42, 42>>})
{:ok, :created}