AzureStorage.Blob (AzureStorage v0.1.5) View Source

Azure Blob Service

Create Azure Blob Service Request Context before using any of the following methods.

{:ok, context} = AzureStorage.create_blob_service("account_name", "account_key")
context |> list_containers()

Link to this section Summary

Functions

Acquires a new lease. If container and blob are specified, acquires a blob lease. Otherwise, if only container is specified and blob is null, acquires a container lease.

The Create Container operation creates a new container under the specified account.

Delete blob witin blob container

The Delete Container operation marks the specified container for deletion.

The Get Blob operation reads or downloads a blob from the system, including its metadata and properties.

The Get Container Metadata operation returns all user-defined metadata for the container.

The Get Container Properties operation returns all user-defined metadata and system properties for the specified container. The data returned does not include the container's list of blobs.

Free acquired lease so other client may immediately acquire a lease against the blob.

The List Blobs operation returns a list of the blobs under the specified container.

The List Containers operation returns a list of the containers under the specified storage account.

The Set Container Metadata operation sets one or more user-defined name-value pairs for the specified container.

Sharing blob file using Share Access Signature

Link to this section Functions

Link to this function

acquire_lease(context, container, filename, options \\ [])

View Source

Acquires a new lease. If container and blob are specified, acquires a blob lease. Otherwise, if only container is specified and blob is null, acquires a container lease.

Supported options

  • :duration - Specifies the duration of the lease, in seconds, or negative on(-1) for a lease that never expires. A non-inifinite lease can be between 15 and 60 seconds. The default value is 15.

  • :propose_lease_id - Proposed lease ID, in a GUID string format. The default value is "".

Link to this function

create_container(context, container)

View Source

The Create Container operation creates a new container under the specified account.

If the container with the same name already exists, the operation fails.

Link to this function

delete_blob(context, container, blob_name)

View Source

Delete blob witin blob container

Link to this function

delete_container(context, container)

View Source

The Delete Container operation marks the specified container for deletion.

The container and any blobs contained within it are later deleted during garbage collection.

Link to this function

get_blob_content(context, container, filename, options \\ [])

View Source

The Get Blob operation reads or downloads a blob from the system, including its metadata and properties.

Supported options

  • :lease_id - Active lease id The default value is "".

  • :json - If true return content is in map() The default value is false.

# get plain/text content
context |> get_blob_content("container1", "data.txt")
{:ok, "Hello World!"}

# get json content
context |> get_blob_content("container1", "data.json", json: true)
{:ok, %{"data" => []}}
Link to this function

get_container_metadata(context, container)

View Source

The Get Container Metadata operation returns all user-defined metadata for the container.

Link to this function

get_container_properties(context, container)

View Source

The Get Container Properties operation returns all user-defined metadata and system properties for the specified container. The data returned does not include the container's list of blobs.

Link to this function

lease_release(context, container, filename, lease_id)

View Source

Free acquired lease so other client may immediately acquire a lease against the blob.

Link to this function

list_blobs(context, container, options \\ [])

View Source

Specs

list_blobs(AzureStorage.Request.Context.t(), String.t(), keyword()) ::
  {:ok, %{Items: list() | [], NextMarker: String.t() | nil}}
  | {:error, String.t()}

The List Blobs operation returns a list of the blobs under the specified container.

Supported options:

  • :max_results - The default value is 1.

  • :marker - false The default value is "".

  • :prefix - false

  • :timeout - false The default value is 30.

Link to this function

list_containers(context, options \\ [])

View Source

Specs

list_containers(AzureStorage.Request.Context.t(), keyword()) ::
  {:ok, %{Items: list() | [], NextMarker: String.t() | nil}}
  | {:error, String.t()}

The List Containers operation returns a list of the containers under the specified storage account.

Supported options:

  • :max_results - The default value is 1.

  • :marker - false The default value is "".

  • :prefix - false

  • :timeout - false The default value is 30.

Link to this function

put_blob(context, container, filename, content, options \\ [])

View Source

Create new blob in a blob container

Supported options

  • :content_type - Content-Type The default value is "text/plain;charset=\"utf-8\"".
{:ok, context} = AzureStorage.create_blob_service("account_name", "account_key")
context |> put_blob("blobs", "cache-key-1.json", "{\"data\": []}", content_type: "application/json;charset=\"utf-8\"")
Link to this function

set_container_metadata(context, container, metadata)

View Source

The Set Container Metadata operation sets one or more user-defined name-value pairs for the specified container.

Link to this function

share(context, options \\ [])

View Source

Sharing blob file using Share Access Signature

Supported options

  • :path - Required. sharing path /<container>/<filename> for example /bookings/hotel-room-a.json

  • :permissions - Required. The default value is "r".

  • :start - Required. Start from date in ISO-8601 format e.g 2021-04-10T10:48:02Z

  • :expiry - Required. Expiry date in ISO-8601 format e.g 2021-04-10T10:48:02Z

Example:

# generate URL for sharing a read only access
context
  |> AzureStorage.Blob.share(
    path: "/bookings/hotel-room-a.json",
    permissions: "r",
    start: "2021-04-10T10:48:02Z",
    expiry: "2021-04-11T13:48:02Z"
    )
  |> HTTPoison.get!([], [ssl: [versions: [:"tlsv1.2"]]])
  |> IO.inspect()