Supabase.Storage.File (supabase_storage v0.4.0)

Represents an Object within a Supabase Storage Bucket.

This module encapsulates the structure and operations related to an object or file stored within a Supabase Storage bucket.

Summary

Types

t()

An Object has the following attributes

Functions

Copies an existing file to a new path in the same bucket.

Creates a signed URL. Use a signed URL to share a file for a fixed amount of time.

Downloads a file from a private bucket. For public buckets, make a request to the URL returned from getPublicUrl instead.

Downloads a file from a private bucket, lazily. For public buckets, make a request to the URL returned from getPublicUrl instead.

Checks the existence of a file.

A simple convenience function to get the URL for an asset in a public bucket. If you do not want to use this function, you can construct the public URL by concatenating the bucket URL with the path to the asset.

Retrieves the details of an existing file.

Lists all the files within a bucket.

Moves an existing file to a new path in the same bucket.

Deletes files within the same bucket

Uploads a file to an existing bucket.

Types

t()

@type t() :: %Supabase.Storage.File{
  bucket: Supabase.Storage.Bucket.t() | nil,
  bucket_id: String.t() | nil,
  created_at: NaiveDateTime.t(),
  id: String.t(),
  last_accessed_at: NaiveDateTime.t(),
  metadata: map(),
  name: String.t(),
  owner: String.t(),
  path: Path.t(),
  updated_at: NaiveDateTime.t()
}

An Object has the following attributes:

  • id: The unique identifier for the object.
  • path: The path to the object within its storage bucket.
  • bucket_id: The ID of the bucket that houses this object.
  • name: The name or title of the object.
  • owner: The owner or uploader of the object.
  • metadata: A map containing meta-information about the object (e.g., file type, size).
  • created_at: Timestamp indicating when the object was first uploaded or created.
  • updated_at: Timestamp indicating the last time the object was updated.
  • last_accessed_at: Timestamp of when the object was last accessed or retrieved.

Functions

copy(s, opts \\ [])

@spec copy(Supabase.Storage.t(), options) :: Supabase.result(:moved)
when options: [
       from: Path.t(),
       to: Path.t(),
       destination_bucket: String.t() | nil
     ]

Copies an existing file to a new path in the same bucket.

Params

  • storage: The Supabase.Storage instance created with Supabase.Storage.from/2.
  • options.from: The original file path, including the current file name. For example folder/image.png.
  • options.to: The new file path, including the new file name. For example folder/image-new.png.
  • options.destination_bucket: The destination bucket ID to move the file if the options.to param refers to another bucket.

create_signed_upload_url(s, object_path, opts \\ [])

@spec create_signed_upload_url(Supabase.Storage.t(), Path.t(), [{:upsert, boolean()}]) ::
  Supabase.result(%{signed_url: String.t(), token: String.t(), path: Path.t()})

Creates a signed upload URL.

Signed upload URLs can be used to upload files to the bucket without further authentication.

They are valid for 2 hours.

Params

  • storage: The Supabase.Storage instance created with Supabase.Storage.from/2.
  • obejct_path: The file path, including the current file name. For example folder/image.png.
  • options.upsert: If set to true, allows the file to be overwritten if it already exists.

create_signed_url(s, path, opts \\ [])

@spec create_signed_url(Supabase.Storage.t(), object_path, options) ::
  Supabase.result(String.t())
when object_path: Path.t(),
     options: [
       download: boolean() | String.t() | nil,
       transform: Enumerable.t() | nil,
       expires_in: integer()
     ]

Creates a signed URL. Use a signed URL to share a file for a fixed amount of time.

Params

  • storage: The Supabase.Storage instance created with Supabase.Storage.from/2.
  • object_path:The file path, including the current file name. For example folder/image.png.
  • options.expires_in: The number of seconds until the signed URL expires. For example, 60 for a URL which is valid for one minute.
  • options.download: Triggers the file as a download if set to true. Set this parameter as the name of the file if you want to trigger the download with a different filename.
  • options.transform: An Enumerable that represents the Supabase.Storage.TransformOptions to transform the asset before serving it to the client.

download(s, path, opts \\ [])

@spec download(Supabase.Storage.t(), path :: Path.t(), options) ::
  Supabase.result(binary())
when options: [{:transform, Enumerable.t() | nil}]

Downloads a file from a private bucket. For public buckets, make a request to the URL returned from getPublicUrl instead.

Params

  • path: The full path and file name of the file to be downloaded. For example folder/image.png.
  • options.transform: Transform the asset before serving it to the client.

download_lazy(s, path, on_response, opts \\ [])

@spec download_lazy(Supabase.Storage.t(), path :: Path.t(), on_response, options) ::
  Supabase.result(binary())
when options: [{:transform, Enumerable.t() | nil}],
     on_response: ({Supabase.Fetcher.status(), Supabase.Fetcher.headers(),
                    binary()} ->
                     Supabase.result(Supabase.Fetcher.Response.t()))

Downloads a file from a private bucket, lazily. For public buckets, make a request to the URL returned from getPublicUrl instead.

Params

  • path: The full path and file name of the file to be downloaded. For example folder/image.png.
  • options.transform: Transform the asset before serving it to the client.

exists?(s, path)

@spec exists?(Supabase.Storage.t(), path :: Path.t()) :: boolean()

Checks the existence of a file.

Params

get_public_url(s, path, opts \\ [])

@spec get_public_url(Supabase.Storage.t(), object_path, options) ::
  Supabase.result(String.t())
when object_path: Path.t(),
     options: [
       download: boolean() | String.t() | nil,
       transform: Enumerable.t() | nil
     ]

A simple convenience function to get the URL for an asset in a public bucket. If you do not want to use this function, you can construct the public URL by concatenating the bucket URL with the path to the asset.

This function does not verify if the bucket is public. If a public URL is created for a bucket which is not public, you will not be able to download the asset.

Params

  • storage: The Supabase.Storage instance created with Supabase.Storage.from/2.
  • path: The path and name of the file to generate the public URL for. For example folder/image.png.
  • options.download: Triggers the file as a download if set to true. Set this parameter as the name of the file if you want to trigger the download with a different filename.
  • options.transform: Supabase.Storage.TransformOptions the asset before serving it to the client, as an Enumerable.

info(s, path)

@spec info(Supabase.Storage.t(), path :: Path.t()) :: Supabase.result(t())

Retrieves the details of an existing file.

Params

list(s, prefix \\ nil, opts \\ %{})

@spec list(Supabase.Storage.t(), Path.t() | nil, options :: Enumerable.t()) ::
  Supabase.result([t()])

Lists all the files within a bucket.

Params

move(s, opts \\ [])

@spec move(Supabase.Storage.t(), options) :: Supabase.result(:moved)
when options: [
       from: Path.t(),
       to: Path.t(),
       destination_bucket: String.t() | nil
     ]

Moves an existing file to a new path in the same bucket.

Params

  • storage: The Supabase.Storage instance created with Supabase.Storage.from/2.
  • options.from: The original file path, including the current file name. For example folder/image.png.
  • options.to: The new file path, including the new file name. For example folder/image-new.png.
  • options.destination_bucket: The destination bucket ID to move the file if the options.to param refers to another bucket.

remove(s, to_remove)

@spec remove(Supabase.Storage.t(), to_remove :: [Path.t()] | Path.t()) ::
  Supabase.result([t()] | t())

Deletes files within the same bucket

Params

upload(s, file_path, object_path, opts \\ %{})

@spec upload(Supabase.Storage.t(), file_path, object_path, options) ::
  Supabase.result(map())
when file_path: Path.t(), object_path: Path.t(), options: Enumerable.t()

Uploads a file to an existing bucket.

Params

upload_to_signed_url(s, token, file_path, object_path, opts \\ %{})

@spec upload_to_signed_url(
  Supabase.Storage.t(),
  token,
  file_path,
  object_path,
  options
) ::
  Supabase.result(map())
when file_path: Path.t(),
     object_path: Path.t(),
     options: Enumerable.t(),
     token: String.t()

Upload a file with a token generated from create_signed_upload_url/3.

Params