Main storage interface that delegates to configured storage adapter.
Configuration
Set the storage adapter in your config:
config :voile, :storage_adapter, Client.Storage.S3Or use environment variable:
export VOILE_STORAGE_ADAPTER="s3" # or "local"The adapter is automatically selected at runtime:
- If VOILE_S3_ACCESS_KEY_ID and VOILE_S3_SECRET_ACCESS_KEY are set, uses S3
- Otherwise, uses Local filesystem storage
Adapters
Client.Storage.Local- Store files on local filesystemClient.Storage.S3- Store files on S3-compatible storage (AWS S3, MinIO, Backblaze B2, etc.)
Summary
Functions
Delete a file using the configured storage adapter.
Generate a presigned URL for the given file key using the configured adapter.
Upload a file using the configured storage adapter.
Functions
Delete a file using the configured storage adapter.
Options
:adapter- Override the default storage adapter:delete_attachment- If true, also delete the attachment record from database (default: false)
Examples
{:ok, url} = Client.Storage.delete(url)
{:ok, url} = Client.Storage.delete(url, adapter: Client.Storage.S3)
{:ok, url} = Client.Storage.delete(url, delete_attachment: true)
Generate a presigned URL for the given file key using the configured adapter.
For S3 adapters this should return a short-lived URL that allows direct GET access to the object. For local adapters it may return {:error, :not_supported}.
Upload a file using the configured storage adapter.
Options
:adapter- Override the default storage adapter:folder- Specify upload folder (e.g., "thumbnails", "attachments"):unit_id- Unit ID for organizing files by unit:generate_filename- Whether to generate a unique filename (default: true):preserve_extension- Whether to preserve original file extension (default: true):create_attachment- Whether to create an attachment record in the database (default: false):attachable_id- ID of the entity the attachment belongs to (required if create_attachment: true):attachable_type- Type of entity the attachment belongs to (required if create_attachment: true):access_level- Access level for the attachment (default: "restricted"):file_type- Type of file (default: inferred from mime_type)
Examples
# Upload with default settings
{:ok, url} = Client.Storage.upload(upload)
# Upload to specific folder
{:ok, url} = Client.Storage.upload(upload, folder: "thumbnails")
# Upload with attachment creation
{:ok, url} = Client.Storage.upload(upload,
create_attachment: true,
attachable_id: user_id,
attachable_type: "User",
access_level: "restricted"
)