CapsuleEcto v1.0.0 Capsule.Ecto View Source
Link to this section Summary
Functions
Processes an upload for each permitted field found in params, calling the
given function to produce a Capsule.Locator and casting it onto the changeset.
Link to this section Types
Specs
changeset() :: Ecto.Changeset.t()
Specs
opts() :: [{:required, boolean()}]
Specs
params() :: map()
Specs
permitted() :: [atom()]
Link to this section Functions
Specs
upload( changeset(), params(), permitted(), (tuple(), changeset() -> Capsule.Locator.t() | changeset()), opts() ) :: changeset()
upload(changeset(), params(), permitted(), module(), atom()) :: changeset()
Processes an upload for each permitted field found in params, calling the
given function to produce a Capsule.Locator and casting it onto the changeset.
The handler function receives {field, value} and the current changeset,
and must return either a Capsule.Locator or an Ecto.Changeset (to add errors).
Options
:required- whentrue, adds a validation error for any permitted field not present in params. Defaults tofalse.
Examples
%MySchema{}
|> Ecto.Changeset.change()
|> Capsule.Ecto.upload(params, [:avatar], fn {_field, upload}, _changeset ->
Capsule.store(upload, MyStorage)
end)
%MySchema{}
|> Ecto.Changeset.change()
|> Capsule.Ecto.upload(params, [:avatar], MyUploader, :upload, required: true)