exfile v0.3.6 Exfile.Ecto View Source

Link to this section Summary

Functions

Prepares Exfile fields to be uploaded before the data is saved to database. Takes a changeset and a list of Exfile fields to prepare the upload on

Link to this section Functions

Link to this function prepare_uploads(changeset, fields) View Source

Prepares Exfile fields to be uploaded before the data is saved to database. Takes a changeset and a list of Exfile fields to prepare the upload on.

Uses Ecto.Changeset.prepare_changes/2 to upload the files.

If a file fails to upload, an exception is thrown and the transaction fails.

For example, in the following code segment,

{:ok, image} = Image.changeset(%Image{}, image_params)
  |> Exfile.Ecto.prepare_uploads([:image])
  |> Repo.insert

the image field is defined in the schema of the Image module. Calling Exfile.Ecto.prepare_uploads with a list of the Exfile fields will prepare them to be uploaded. Note that if the changeset is not valid, the files will not be uploaded.