View Source Azurex.Blob (AzureX v1.1.0)

Implementation of Azure Blob Storage.

In the functions below set container as nil to use the one configured in Azurex.Blob.Config.

Summary

Functions

Returns the url for a container (defaults to the one in Azurex.Blob.Config)

Returns the url for a file in a container (defaults to the one in Azurex.Blob.Config)

Checks if a blob exists, and returns metadata for the blob if it does

Lists all blobs in a container

Functions

Link to this function

copy_blob(source_name, destination_name, container \\ nil)

View Source
@spec copy_blob(String.t(), String.t(), optional_string()) ::
  {:ok, HTTPoison.Response.t()} | {:error, term()}

Copies a blob to a destination.

Link to this function

delete_blob(name, container \\ nil, params \\ [])

View Source
Link to this function

get_blob(name, container \\ nil, params \\ [])

View Source

Download a blob

Examples

iex> get_blob("filename.txt")
{:ok, "file contents"}

iex> get_blob("filename.txt", "container")
{:ok, "file contents"}

iex> get_blob("filename.txt", nil, timeout: 10)
{:ok, "file contents"}

iex> get_blob("filename.txt")
{:error, %HTTPoison.Response{}}
@spec get_url(optional_string()) :: String.t()

Returns the url for a container (defaults to the one in Azurex.Blob.Config)

Link to this function

get_url(container, blob_name)

View Source
@spec get_url(optional_string(), String.t()) :: String.t()

Returns the url for a file in a container (defaults to the one in Azurex.Blob.Config)

Link to this function

head_blob(name, container \\ nil, params \\ [])

View Source

Checks if a blob exists, and returns metadata for the blob if it does

Link to this function

list_blobs(container \\ nil, params \\ [])

View Source

Lists all blobs in a container

Examples

iex> Azurex.Blob.list_blobs()
{:ok, "<?xml ...."}

iex> Azurex.Blob.list_blobs()
{:error, %HTTPoison.Response{}}
Link to this function

put_blob(name, blob, content_type, container \\ nil, params \\ [])

View Source
@spec put_blob(
  String.t(),
  binary() | {:stream, Enumerable.t()},
  optional_string(),
  optional_string(),
  keyword()
) ::
  :ok
  | {:error,
     HTTPoison.AsyncResponse.t() | HTTPoison.Error.t() | HTTPoison.Response.t()}

Upload a blob.

The blob Argument

The blob argument may be either a binary or a tuple of {:stream, Stream.t()}.

The content_type Argument

This argument can be either a valid string, or nil. A content_type argument of nil will result in the blob being assigned the default content type "application/octet-stream".

Examples

iex> put_blob("filename.txt", "file contents", "text/plain")
:ok

iex> {:ok, io_device} = StringIO.open("file contents as a stream")
byte_length = 8_000_000
bitstream = IO.binstream(io_device, byte_length)
put_blob("filename.txt", {:stream, bitstream}, nil)
:ok

iex> put_blob("filename.txt", "file contents", "text/plain", "container")
:ok

iex> put_blob("filename.txt", "file contents", "text/plain", nil, timeout: 10)
:ok

iex> put_blob("filename.txt", "file contents", "text/plain")
{:error, %HTTPoison.Response{}}