Upload.Uploader behaviour (upload v0.3.0)

This is a behaviour that defines how an uploader should behave. It comes in handy if you want to validate uploads or transform files before uploading.

Example

defmodule MyUploader do

  use Upload.Uploader

  def cast(file) do
    with {:ok, upload} <- Upload.cast(file) do
      extension = Upload.get_extension(upload)

      if Enum.member?(~w(.png), extension) do
        {:ok, upload}
      else
        {:error, "not a valid file extension"}
      end
    end
  end
end

Link to this section Summary

Link to this section Callbacks

Specs

cast(Upload.uploadable()) :: {:ok, Upload.t()} | {:error, String.t()} | :error
Link to this callback

cast(arg1, list)

Specs

cast(Upload.uploadable(), list()) ::
  {:ok, Upload.t()} | {:error, String.t()} | :error
Link to this callback

cast_path(arg1)

Specs

cast_path(Upload.uploadable_path()) ::
  {:ok, Upload.t()} | {:error, String.t()} | :error
Link to this callback

cast_path(arg1, list)

Specs

cast_path(Upload.uploadable_path(), list()) ::
  {:ok, Upload.t()} | {:error, String.t()} | :error

Specs

transfer(Upload.t()) :: {:ok, Upload.transferred()} | {:error, any()}