Bunnyx.Storage (Bunnyx v0.3.0)

Copy Markdown View Source

Edge storage lets you store and serve files directly from bunny.net's network, without needing your own origin server.

Storage uses a separate client from the main API because it has its own authentication (a per-zone storage password) and a different base URL. Create one with Bunnyx.Storage.new/1.

Usage

client = Bunnyx.Storage.new(storage_key: "pw-...", zone: "my-zone")

{:ok, objects} = Bunnyx.Storage.list(client, "/images/")
{:ok, binary} = Bunnyx.Storage.get(client, "/images/logo.png")
{:ok, nil} = Bunnyx.Storage.put(client, "/images/new.png", data)
{:ok, nil} = Bunnyx.Storage.delete(client, "/images/old.png")

For storage zones in a specific region, pass the :region option:

client = Bunnyx.Storage.new(storage_key: "pw-...", zone: "my-zone", region: "de")

Summary

Functions

Deletes a file.

Downloads a file and returns its binary content.

Lists files and directories at the given path.

Creates a new storage client.

Types

t()

@type t() :: %Bunnyx.Storage{req: Req.Request.t(), zone: String.t()}

Functions

delete(client, path)

@spec delete(t() | keyword(), String.t()) :: {:ok, nil} | {:error, Bunnyx.Error.t()}

Deletes a file.

get(client, path)

@spec get(t() | keyword(), String.t()) :: {:ok, binary()} | {:error, Bunnyx.Error.t()}

Downloads a file and returns its binary content.

list(client, path \\ "/")

@spec list(t() | keyword(), String.t()) ::
  {:ok, [Bunnyx.Storage.Object.t()]} | {:error, Bunnyx.Error.t()}

Lists files and directories at the given path.

new(opts)

@spec new(keyword()) :: t()

Creates a new storage client.

Options

  • :storage_key (required) — your storage zone password
  • :zone (required) — the storage zone name
  • :region — storage region (e.g. "de", "ny"). Defaults to the primary region.
  • :receive_timeout — socket receive timeout in milliseconds (default 15_000)
  • :finch — a custom Finch pool name

put(client, path, data, opts \\ [])

@spec put(t() | keyword(), String.t(), binary(), keyword()) ::
  {:ok, nil} | {:error, Bunnyx.Error.t()}

Uploads a file.

Options

  • :content_type — MIME type (e.g. "image/png", "application/json")
  • :checksum — SHA-256 checksum for integrity verification