Plato.Storage.Adapter behaviour (plato v0.0.24)

Copy Markdown View Source

Behaviour for storage adapters in Plato CMS.

Allows pluggable storage backends (S3, local filesystem, etc.)

Summary

Callbacks

Delete a file from storage

Check if a file exists in storage

Get a URL for accessing the stored file

Upload a file to storage

Types

config()

@type config() :: keyword()

storage_path()

@type storage_path() :: String.t()

upload()

@type upload() :: %{filename: String.t(), path: String.t(), content_type: String.t()}

url()

@type url() :: String.t()

Callbacks

delete(storage_path, config)

@callback delete(storage_path(), config()) :: :ok | {:error, term()}

Delete a file from storage

exists?(storage_path, config)

@callback exists?(storage_path(), config()) :: boolean()

Check if a file exists in storage

get_url(storage_path, config)

@callback get_url(storage_path(), config()) :: {:ok, url()} | {:error, term()}

Get a URL for accessing the stored file

put(upload, storage_path, config)

@callback put(upload(), storage_path(), config()) ::
  {:ok, storage_path()} | {:error, term()}

Upload a file to storage