View Source Mobilizon.Web.Upload (Mobilizon v5.0.0-beta.1)

Manage user uploads

Options:

  • :type: presets for activity type (defaults to Document) and size limits from app configuration
  • :description: upload alternative text
  • :base_url: override base url
  • :uploader: override uploader
  • :filters: override filters
  • :size_limit: override size limit
  • :activity_type: override activity type

The %Mobilizon.Web.Upload{} struct: all documented fields are meant to be overwritten in filters:

  • :id - the upload id.
  • :name - the upload file name.
  • :path - the upload path: set at first to id/name but can be changed. Keep in mind that the path is once created permanent and changing it (especially in uploaders) is probably a bad idea!
  • :tempfile - path to the temporary file. Prefer in-place changes on the file rather than changing the path as the temporary file is also tracked by Plug.Upload{} and automatically deleted once the request is over.

Related behaviors:

Summary

Types

@type option() ::
  {:type, :avatar | :banner | :background}
  | {:description, String.t()}
  | {:activity_type, String.t()}
  | {:size_limit, nil | non_neg_integer()}
  | {:uploader, module()}
  | {:filters, [module()]}
  | {:allow_list_mime_types, boolean()}
@type source() ::
  Plug.Upload.t()
  | (data_uri_string :: String.t())
  | {:from_local, name :: String.t(), id :: String.t(), path :: String.t()}
@type t() :: %Mobilizon.Web.Upload{
  blurhash: String.t(),
  content_type: String.t(),
  height: integer(),
  id: String.t(),
  name: String.t(),
  path: String.t(),
  size: integer(),
  tempfile: String.t(),
  url: term(),
  width: integer()
}

Functions

@spec remove(String.t()) :: {:ok, String.t()} | {:error, atom()}
Link to this function

store(upload, opts \\ [])

View Source
@spec store(source(), options :: [option()]) ::
  {:ok, t()} | {:error, String.t()} | {:error, atom()}