Uploadex v1.0.1 Uploadex.Uploader behaviour View Source
Behaviour of an Uploader.
Example
defmodule MyApp.Uploader do
@moduledoc false
@behaviour Uploadex.Uploader
alias MyAppWeb.Endpoint
@impl true
def get_files(%User{photo: photo}), do: photo
def get_files(%Company{photo: photo}), do: photo
@impl true
def default_opts(Uploadex.FileStorage), do: [base_path: :code.priv_dir(:my_app), base_url: Endpoint.url()]
def default_opts(Uploadex.S3Storage), do: [bucket: "my_bucket", base_url: "https://my_bucket.s3-sa-east-1.amazonaws.com", upload_opts: [acl: :public_read]]
@impl true
def storage(%User{} = user), do: {Uploadex.FileStorage, directory: storage_dir(user)}
def storage(%Company{} = company), do: {Uploadex.S3Storage, directory: storage_dir(company)}
def storage_dir(%User{id: user_id}), do: "/uploads/users/#{user_id}"
def storage_dir(%Company{}), do: "/thumbnails"
end
Link to this section Summary
Link to this section Types
Link to this type
file() View Source
Link to this type
record()
View Source
record()
View Source
record() :: any()
record() :: any()
Link to this section Callbacks
Link to this callback
default_opts(module) View Source
Link to this callback
get_files(record) View Source
Link to this callback