PhoenixKit.Storage.Provider behaviour (phoenix_kit v1.6.15)
View SourceBehavior for storage providers.
Each storage provider (local, S3, B2, R2) must implement this behavior to provide file storage and retrieval capabilities.
Summary
Callbacks
Deletes a file from the storage provider.
Checks if a file exists in the storage provider.
Gets a public URL for a file in the storage provider.
Retrieves a file from the storage provider.
Stores a file in the storage provider.
Tests the connection to the storage provider.
Callbacks
@callback delete_file(bucket :: PhoenixKit.Storage.Bucket.t(), file_path :: String.t()) :: :ok | {:error, term()}
Deletes a file from the storage provider.
Parameters
bucket- The bucket configurationfile_path- Path to the file in storage
Returns
:ok- File deleted successfully{:error, reason}- Failed to delete file
@callback file_exists?(bucket :: PhoenixKit.Storage.Bucket.t(), file_path :: String.t()) :: boolean()
Checks if a file exists in the storage provider.
Parameters
bucket- The bucket configurationfile_path- Path to the file in storage
Returns
trueif file exists,falseotherwise
@callback public_url(bucket :: PhoenixKit.Storage.Bucket.t(), file_path :: String.t()) :: String.t() | nil
Gets a public URL for a file in the storage provider.
Parameters
bucket- The bucket configurationfile_path- Path to the file in storage
Returns
- Public URL string or
nilif not applicable
@callback retrieve_file( bucket :: PhoenixKit.Storage.Bucket.t(), file_path :: String.t(), destination_path :: String.t() ) :: :ok | {:error, term()}
Retrieves a file from the storage provider.
Parameters
bucket- The bucket configurationfile_path- Path to the file in storagedestination_path- Local path where to save the file
Returns
{:ok, file_path}- File retrieved successfully{:error, reason}- Failed to retrieve file
@callback store_file( bucket :: PhoenixKit.Storage.Bucket.t(), source_path :: String.t(), destination_path :: String.t(), opts :: keyword() ) :: {:ok, String.t()} | {:error, term()}
Stores a file in the storage provider.
Parameters
bucket- The bucket configurationsource_path- Path to the source file on local filesystemdestination_path- Relative path where to store the fileopts- Additional options
Returns
{:ok, url}- File stored successfully, returns public URL{:error, reason}- Failed to store file
@callback test_connection(bucket :: PhoenixKit.Storage.Bucket.t()) :: :ok | {:error, term()}
Tests the connection to the storage provider.
Parameters
bucket- The bucket configuration
Returns
:ok- Connection successful{:error, reason}- Connection failed