View Source Uploadex.Context (Uploadex v3.1.0)

Context Helper functions for handling files.

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

iex> Uploadex.Context.create_with_file(changeset, Repo, MyUploader)
{:ok, %User{}}

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

iex> MyUploader.create_with_file(changeset)
{:ok, %User{}}

Summary

Functions

Inserts the changeset and store the record files in a database transaction, so if the files fail to be stored the record will not be created.

Deletes the record and all of its files. This is not in a database transaction, since the delete operation never returns errors.

Updates the record and its files in a database transaction, so if the files fail to be stored the record will not be created.

Similar to update_with_file/3, but does not delete previous files.

Functions

Link to this function

create_with_file(changeset, repo, uploader, opts \\ [])

View Source
@spec create_with_file(Ecto.Changeset.t(), module(), Uploadex.Uploader.t(), keyword()) ::
  {:ok, any()} | {:error, any()}

Inserts the changeset and store the record files in a database transaction, so if the files fail to be stored the record will not be created.

Link to this function

delete_with_file(record_or_changeset, repo, uploader, opts \\ [])

View Source
@spec delete_with_file(any(), module(), Uploadex.Uploader.t(), keyword()) ::
  {:ok, any()} | {:error, any()}

Deletes the record and all of its files. This is not in a database transaction, since the delete operation never returns errors.

Link to this function

update_with_file(changeset, previous_record, repo, uploader, opts \\ [])

View Source
@spec update_with_file(
  Ecto.Changeset.t(),
  any(),
  module(),
  Uploadex.Uploader.t(),
  keyword()
) ::
  {:ok, any()} | {:error, any()}

Updates the record and its files in a database transaction, so if the files fail to be stored the record will not be created.

This function also deletes files that are no longer referenced.

Link to this function

update_with_file_keep_previous(changeset, repo, uploader, opts \\ [])

View Source
@spec update_with_file_keep_previous(
  Ecto.Changeset.t(),
  module(),
  Uploadex.Uploader.t(),
  keyword()
) ::
  {:ok, any()} | {:error, any()}

Similar to update_with_file/3, but does not delete previous files.