Supabase.Storage.File (supabase_storage v0.4.2)
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
Functions
Copies an existing file to a new path in the same bucket.
Creates a signed upload URL.
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.
Upload a file with a token generated from create_signed_upload_url/3
.
Types
@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
@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
: TheSupabase.Storage
instance created withSupabase.Storage.from/2
.options.from
: The original file path, including the current file name. For examplefolder/image.png
.options.to
: The new file path, including the new file name. For examplefolder/image-new.png
.options.destination_bucket
: The destination bucket ID to move the file if theoptions.to
param refers to another bucket.
@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
: TheSupabase.Storage
instance created withSupabase.Storage.from/2
.obejct_path
: The file path, including the current file name. For examplefolder/image.png
.options.upsert
: If set to true, allows the file to be overwritten if it already exists.
@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
: TheSupabase.Storage
instance created withSupabase.Storage.from/2
.object_path
:The file path, including the current file name. For examplefolder/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
: AnEnumerable
that represents theSupabase.Storage.TransformOptions
to transform the asset before serving it to the client.
@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 examplefolder/image.png
.options.transform
: Transform the asset before serving it to the client.
@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 examplefolder/image.png
.options.transform
: Transform the asset before serving it to the client.
@spec exists?(Supabase.Storage.t(), path :: Path.t()) :: boolean()
Checks the existence of a file.
Params
storage
: TheSupabase.Storage
instance created withSupabase.Storage.from/2
.path
@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
: TheSupabase.Storage
instance created withSupabase.Storage.from/2
.path
: The path and name of the file to generate the public URL for. For examplefolder/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 anEnumerable
.
@spec info(Supabase.Storage.t(), path :: Path.t()) :: Supabase.result(t())
Retrieves the details of an existing file.
Params
storage
: TheSupabase.Storage
instance created withSupabase.Storage.from/2
.path
@spec list(Supabase.Storage.t(), Path.t() | nil, options :: Enumerable.t()) :: Supabase.result([t()])
Lists all the files within a bucket.
Params
storage
: TheSupabase.Storage
instance created withSupabase.Storage.from/2
.prefix
: The folder path.options
: AnEnumerable
that represents theElixir.Supabase.Storage.SearchOptions
.
@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
: TheSupabase.Storage
instance created withSupabase.Storage.from/2
.options.from
: The original file path, including the current file name. For examplefolder/image.png
.options.to
: The new file path, including the new file name. For examplefolder/image-new.png
.options.destination_bucket
: The destination bucket ID to move the file if theoptions.to
param refers to another bucket.
@spec remove(Supabase.Storage.t(), to_remove :: [Path.t()] | Path.t()) :: Supabase.result([t()] | t())
Deletes files within the same bucket
Params
storage
: TheSupabase.Storage
instance created withSupabase.Storage.from/2
.paths
: An array of files to delete, including the path and file name. For example["folder/image.png"]
.
@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
storage
: TheSupabase.Storage
instance created withSupabase.Storage.from/2
.file_path
: The local filesystem path, to upload from.object_path
: The file path, including the file name. Should be of the formatfolder/subfolder/filename.png
. The bucket must already exist before attempting to upload.options
: OptionalEnumerable
that represents theSupabase.Storage.FileOptions
.
@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
storage
: TheSupabase.Storage
instance created withSupabase.Storage.from/2
.token
: token The token generated fromcreate_signed_upload_url/3
.file_path
: The local filesystem path, to upload from.object_path
: The file path, including the file name. Should be of the formatfolder/subfolder/filename.png
. The bucket must already exist before attempting to upload.options
: OptionalEnumerable
that represents theSupabase.Storage.FileOptions
.