Supabase.Storage (supabase_storage v0.4.0)

Supabase.Storage Elixir Package

This module provides integration with the Supabase Storage API, enabling developers to perform a multitude of operations related to buckets and objects with ease.

Usage

You can start by creating or managing buckets:

Supabase.Storage.create_bucket(client, "my_new_bucket")

Once a bucket is set up, objects within the bucket can be managed:

Supabase.Storage.upload_object(client, "my_bucket", "path/on/server.png", "path/on/local.png")

Examples

Here are some basic examples:

# Removing an object
Supabase.Storage.remove_object(client, "my_bucket", "path/on/server.png")

# Moving an object
Supabase.Storage.move_object(client, "my_bucket", "path/on/server1.png", "path/on/server2.png")

Ensure to refer to method-specific documentation for detailed examples and explanations.

Permissions

Do remember to check and set the appropriate permissions in Supabase to make sure that the operations can be performed without any hitches.

Summary

Types

t()

Represent an instance of the Storage service to interact with the Supabase.Storage.File API.

Functions

Creates a new bucket in the current project given a map of attributes.

Deletes a bucket in the current project. Notice that this also deletes all objects in the bucket.

Empties a bucket in the current project. This action deletes all objects in the bucket.

Creates an instance of Supabase.Storage so you can interact with the Supabase.Storage.File API.

Retrieves information about a bucket in the current project.

Retrieves information about all buckets in the current project.

Updates a bucket in the current project given a map of attributes.

Types

t()

@type t() :: %Supabase.Storage{bucket_id: String.t(), client: Supabase.Client.t()}

Represent an instance of the Storage service to interact with the Supabase.Storage.File API.

Functions

create_bucket(client, id, attrs \\ %{})

Creates a new bucket in the current project given a map of attributes.

Params

  • client: The Supabase.Client to use to interact with the Storage service.
  • id: A unique identifier for the bucket you are creating.
  • options.public: The visibility of the bucket. Public buckets don't require an authorization token to download objects, but still require a valid token for all other operations. By default, buckets are private.
  • options.file_size_limit: Specifies the max file size in bytes that can be uploaded to this bucket. The global file size limit takes precedence over this value. The default value is nil, which doesn't set a per bucket file size limit.
  • options.allowed_mime_types: Specifies the allowed mime types that this bucket can accept during upload. The default value is nil, which allows files with all mime types to be uploaded. Each mime type specified can be a wildcard, e.g. image/*, or a specific mime type, e.g. image/png.

Examples

iex> Supabase.Storage.create_bucket(client, "avatars")
{:ok, %Supabase.Storage.Bucket{...}}

iex> Supabase.Storage.create_bucket(client, "avatars", %{file_size_limit: "100mb"})
{:ok, %Supabase.Storage.Bucket{...}}

iex> Supabase.Storage.create_bucket(client, "avatars")
{:error, %Supabase.Error{...}}

delete_bucket(client, id)

Deletes a bucket in the current project. Notice that this also deletes all objects in the bucket.

Params

  • client: The Supabase.Client to use to interact with the Storage service.
  • id: The unique identifier of the bucket you would like to empty.

Examples

iex> Supabase.Storage.delete_bucket(client, "avatars")
{:ok, :deleted}

iex> Supabase.Storage.delete_bucket(client, "avatars")
{:error, %Supabase.Error{...}}

empty_bucket(client, id)

Empties a bucket in the current project. This action deletes all objects in the bucket.

Params

  • client: The Supabase.Client to use to interact with the Storage service.
  • id: The unique identifier of the bucket you would like to empty.

Examples

iex> Supabase.Storage.empty_bucket(client, "avatars")
{:ok, :emptied}

iex> Supabase.Storage.empty_bucket(client, "avatars")
{:error, %Supabase.Error{...}}

from(client, bucket_id)

Creates an instance of Supabase.Storage so you can interact with the Supabase.Storage.File API.

Params

  • client: The Supabase.Client to use to interact with the Storage service.
  • bucket_id: The unique identifier of the Bucket to operate within

get_bucket(client, id)

Retrieves information about a bucket in the current project.

Params

  • client: The Supabase.Client to use to interact with the Storage service.
  • id: The unique identifier of the bucket you would like to retrieve.

Examples

iex> Supabase.Storage.retrieve_bucket_info(client, "avatars")
{:ok, %Supabase.Storage.Bucket{...}}

iex> Supabase.Storage.retrieve_bucket_info(client, "non-existant")
{:error, %Supabase.Error{...}}

list_buckets(client)

Retrieves information about all buckets in the current project.

Params

Examples

iex> Supabase.Storage.list_buckets(client)
{:ok, [%Supabase.Storage.Bucket{...}, ...]}

iex> Supabase.Storage.list_buckets(client)
{:error, %Supabase.Error{}}

update_bucket(client, id, attrs)

Updates a bucket in the current project given a map of attributes.

Params

  • client: The Supabase.Client to use to interact with the Storage service.
  • id: A unique identifier for the bucket you are creating.
  • options.public: The visibility of the bucket. Public buckets don't require an authorization token to download objects, but still require a valid token for all other operations. By default, buckets are private.
  • options.file_size_limit: Specifies the max file size in bytes that can be uploaded to this bucket. The global file size limit takes precedence over this value. The default value is nil, which doesn't set a per bucket file size limit.
  • options.allowed_mime_types: Specifies the allowed mime types that this bucket can accept during upload. The default value is nil, which allows files with all mime types to be uploaded. Each mime type specified can be a wildcard, e.g. image/*, or a specific mime type, e.g. image/png.

Examples

iex> Supabase.Storage.update_bucket(client, "avatars", %{public: true})
{:ok, %Supabase.Storage.Bucket{...}}

iex> Supabase.Storage.update_bucket(client, "avatars", %{public: true})
{:error, %Supabase.Error{...}}