View Source Uploadex.Files (Uploadex v3.1.0)

Functions to store and delete files.

Note that all functions in this module require the Uploader as an argument. You are free to call them like that:

iex> Uploadex.Files.store_files(user, MyUploader)
{:ok, %User{}}

However, by doing use Uploadex in your uploader, you can call these functions directly through the uploader to avoid having to pass this extra argument around:

iex> MyUploader.store_files(user)
{:ok, %User{}}

Summary

Types

@type record() :: any()
@type record_field() :: atom()
@type status() :: :ok | :error

Functions

Link to this function

delete_files(record, uploader)

View Source
@spec delete_files(record(), Uploadex.Uploader.t()) ::
  {:ok, record()} | {:error, any()}

Deletes all files for a record.

Link to this function

delete_previous_files(new_record, previous_record, uploader)

View Source
@spec delete_previous_files(record(), record(), Uploadex.Uploader.t()) ::
  {:ok, record()} | {:error, any()}

Deletes all files that changed.

Link to this function

get_file_url(record, file, field, uploader)

View Source
@spec get_file_url(record(), String.t(), record_field(), Uploadex.Uploader.t()) ::
  {status(), String.t() | nil}
Link to this function

get_files_url(record, field, uploader)

View Source
@spec get_files_url(record(), record_field(), Uploadex.Uploader.t()) ::
  {status(), [String.t()]}
Link to this function

get_files_url(record, files, field, uploader)

View Source
@spec get_files_url(
  record(),
  String.t() | [String.t()],
  record_field(),
  Uploadex.Uploader.t()
) ::
  {status(), [String.t()]}
Link to this function

get_temporary_file(record, file, path, field, uploader)

View Source
@spec get_temporary_file(
  record(),
  String.t(),
  String.t(),
  record_field(),
  Uploadex.Uploader.t()
) ::
  String.t() | nil | {:error, String.t()}
Link to this function

get_temporary_files(record, path, field, uploader)

View Source
@spec get_temporary_files(record(), String.t(), record_field(), Uploadex.Uploader.t()) ::
  [String.t()]
Link to this function

get_temporary_files(record, files, path, field, uploader)

View Source
@spec get_temporary_files(
  record(),
  String.t() | [String.t()],
  String.t(),
  record_field(),
  Uploadex.Uploader.t()
) :: [String.t()]
Link to this function

store_files(record, uploader)

View Source
@spec store_files(record(), Uploadex.Uploader.t()) ::
  {:ok, record()} | {:error, any()}

Stores all files of a record, as defined by the uploader.

Files that are not maps are ignored, which allows for assigning an existing file to a record without recreating it, by simply passing it's filename.

Link to this function

store_files(record, previous_record, uploader)

View Source
@spec store_files(record(), record(), Uploadex.Uploader.t()) ::
  {:ok, record()} | {:error, any()}