Storehouse.Ecto.File (Storehouse v0.1.0)

Copy Markdown View Source

An Ecto type for a stored file (Storehouse.File) in a record's column: a map (jsonb in PostgreSQL) of its key, URL, name, type, size, checksum, width and height. No table of files: the record has its file.

schema "users" do
  field :avatar, Storehouse.Ecto.File
  field :photos, {:array, Storehouse.Ecto.File}, default: []
end

# The migration
add :avatar, :map
add :photos, {:array, :map}, default: []

It casts a Storehouse.File only, never a map of a form's params: a file's key comes from Storehouse, never from a browser, so that no one puts another's file in their record. Put files with Storehouse.Ecto.put_file/4.