Uploader v0.2.0 Uploader.Ecto.UploadableFields behaviour View Source
Provides a macro for defining uploadable fields.
When calling uploadable_field/2, two fields are created:
- a virtual field is created named by the given name prefixed by "uploaded_"
and holds the
Plug.Uploadstruct (representing the uploaded file). a field with the given name is created holding the casted
Plug.Uploadstruct (typically the struct is casted into a filename).The code below
uploadable_field :imagewill generate
field :image, :string field :uploaded_image, :any, virtual: true
Using this module (use) provides the caller module with the function
get_uploadable_fields\0 listing all the uploadable fields and their options.
The following options may be given to uploadable fields:
:cast: a function that casts aPlug.Uploadstruct into the value to be stored in the database.directory: the base directory containing the file uploads.filename: a function that generates the filename based on the given struct.on_file_exists: specifies the strategy to apply if the file path already exists. Its value may be::overwrite: overwrite the file if the file path already exists:compare_hash: do not copy the file if the file path already exists; if the hashes of the files' content are not equal, return an error.
print: a function that prints the field (typically used be the view).type: the field type.