Pleroma v1.1.9-10-g42f76306+dev Pleroma.Uploaders.Uploader behaviour View Source

Defines the contract to put and get an uploaded file to any backend.

Link to this section Summary

Callbacks

Instructs how to get the file from the backend.

Put a file to the backend.

Link to this section Types

Link to this type

file_spec()

View Source
file_spec() :: {:file | :url, String.t()}
Link to this type

get_method()

View Source
get_method() ::
  {:static_dir, directory :: String.t()} | {:url, url :: String.t()}

Link to this section Functions

Link to this function

put_file(uploader, upload)

View Source
put_file(module(), Pleroma.Upload.t()) ::
  {:ok, file_spec()} | {:error, String.t()}

Link to this section Callbacks

Link to this callback

get_file(file)

View Source
get_file(file :: String.t()) :: {:ok, get_method()}

Instructs how to get the file from the backend.

Used by Pleroma.Plugs.UploadedMedia.

Link to this callback

http_callback(arg1, arg2)

View Source (optional)
http_callback(Plug.Conn.t(), Map.t()) ::
  {:ok, Plug.Conn.t()}
  | {:ok, Plug.Conn.t(), file_spec()}
  | {:error, Plug.Conn.t(), String.t()}
Link to this callback

put_file(arg1)

View Source
put_file(Pleroma.Upload.t()) ::
  :ok | {:ok, file_spec()} | {:error, String.t()} | :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 with get_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 bypass get_file/2 and use the url 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's http_callback/3 method.