Miosa.Storage (Miosa v1.0.1)

Copy Markdown View Source

Managed S3-compatible object storage — buckets, objects, presigned URLs.

Object keys are URL-encoded before inclusion in path segments. Mutating bucket operations send an Idempotency-Key header automatically.

Example

client = Miosa.client(System.fetch_env!("MIOSA_API_KEY"))

{:ok, bucket} = Miosa.Storage.create_bucket(client, %{name: "assets"})
{:ok, result} = Miosa.Storage.presign(client, bucket["id"], %{
  key: "uploads/logo.png",
  operation: "put",
  expires_in_sec: 600
})
IO.puts(result["url"])

Summary

Functions

Create a storage bucket.

Delete a bucket by ID.

Delete an object from a bucket. The key is URL-encoded automatically.

Fetch a bucket by ID.

Download the raw bytes of an object.

List all storage buckets for the authenticated tenant.

Mint a presigned URL for direct browser upload or download.

Upload bytes to an object key in a bucket.

Functions

create_bucket(client, attrs)

@spec create_bucket(Miosa.Client.t(), map()) :: Miosa.Client.result(map())

Create a storage bucket.

Required: :name. Optional: :region, :public, and any other attrs. Pass :idempotency_key in attrs to supply your own idempotency key.

delete_bucket(client, bucket_id)

@spec delete_bucket(Miosa.Client.t(), String.t()) :: Miosa.Client.result(map())

Delete a bucket by ID.

delete_object(client, bucket_id, key)

@spec delete_object(Miosa.Client.t(), String.t(), String.t()) ::
  Miosa.Client.result(map())

Delete an object from a bucket. The key is URL-encoded automatically.

get_bucket(client, bucket_id)

@spec get_bucket(Miosa.Client.t(), String.t()) :: Miosa.Client.result(map())

Fetch a bucket by ID.

get_object(client, bucket_id, key)

@spec get_object(Miosa.Client.t(), String.t(), String.t()) ::
  Miosa.Client.result(binary())

Download the raw bytes of an object.

The key is URL-encoded before being placed in the path.

list_buckets(client)

@spec list_buckets(Miosa.Client.t()) :: Miosa.Client.result(map())

List all storage buckets for the authenticated tenant.

list_objects(client, bucket_id, opts \\ [])

@spec list_objects(Miosa.Client.t(), String.t(), keyword() | map()) ::
  Miosa.Client.result(map())

List objects in a bucket.

Options:

  • :prefix — Filter by key prefix.
  • :limit — Max objects to return.
  • :cursor — Pagination cursor.

presign(client, bucket_id, attrs)

@spec presign(Miosa.Client.t(), String.t(), map()) :: Miosa.Client.result(map())

Mint a presigned URL for direct browser upload or download.

Required attrs:

  • :key — Object key.

Optional attrs:

  • :operation"get" (default) or "put".
  • :expires_in_sec — Expiry in seconds. Defaults to 300.
  • :content_type — Required for "put" uploads.

put_object(client, bucket_id, key, content, opts \\ [])

@spec put_object(Miosa.Client.t(), String.t(), String.t(), binary(), keyword()) ::
  Miosa.Client.result(map())

Upload bytes to an object key in a bucket.

content_type defaults to "application/octet-stream". The key is URL-encoded before being placed in the path.