View Source Mobilizon.Web.Upload.Uploader behaviour (Mobilizon v5.0.0-beta.1)
Defines the contract to put and get an uploaded file to any backend.
Summary
Types
@type file_spec() :: {:file | :url, String.t()}
Callbacks
@callback get_file(file :: String.t()) :: {:ok, get_method()}
Instructs how to get the file from the backend.
Used by Mobilizon.Web.Plugs.UploadedMedia
.
@callback http_callback(Plug.Conn.t(), map()) :: {:ok, Plug.Conn.t()} | {:ok, Plug.Conn.t(), file_spec()} | {:error, Plug.Conn.t(), String.t()}
@callback put_file(Mobilizon.Web.Upload.t()) :: :ok | {:ok, file_spec()} | {:error, atom()} | :wait_callback
Put a file to the backend.
Returns:
:ok
which assumes{:ok, upload.path}
{:ok, spec}
where spec is:{:file, filename :: String.t}
to handle reads withget_file/1
(recommended)
This allows to correctly proxy or redirect requests to the backend, while allowing to migrate backends without breaking any URL.
{url, url :: String.t}
to bypassget_file/2
and use theurl
directly in the activity.{:error, String.t}
error information if the file failed to be saved to the backend.:wait_callback
will wait for an http post request at/api/pleroma/upload_callback/:upload_path
and call the uploader'shttp_callback/3
method.
Functions
@spec put_file(module(), Mobilizon.Web.Upload.t()) :: {:ok, file_spec()} | {:error, atom()}