View Source Tempel.Gate behaviour (Tempel v0.2.1)
Summary
Provides functionality to creates uploader modules
Examples
defmodule MyUploader do
use Tempel.Gate
def init(opts \\ %{}) do
# do something to warmup the uploader and return a map
opts
end
@impl true
def pipeline(:profile, files, options) do
create_variants(files, variants: [
thumbnail: [
operation: :thumbnail,
resize_options: [size: "300x400", options: [fit: :cover]],
filename: name, _opts ->
"thumbnails/" <> options[:user_id] <>"/" <> name
end
]
], save_original: true)
end
end
this uploader is fully functional, cann be invoked from different modules.
MyUploader.save(:profile, file, %{"user_id": 10})
# => {:ok, %{"thumbnail": "thumbnails/10/file.jpg", "main" => "file.jpg"}}
For files without variants such as document/pdf we can use no_variants/2
defmodule MyUploader do
# all other code
def pipeline(:document, files, options) do
no_variants(files, filename: name, _opts -> "document/" <> options["user_id"] <> "/" <> name end)
end
end
MyUploader.save(:document, file, %{"user_id": 10})
# => {:ok, %{"main" => "document/10/file.pdf"}}
Available types:
file()
is structured to match the format of Plug.Uploadfileio()
is structured likefile()
. But instead of the file path it contains the IO data in key:iodata
Link to this section Summary
Types
This type is stuctured like the format of Plug.Upload
fileio()
is structured like file()
. But instead of the file path it contains the IO data in key :iodata
mainly the result from variant generation in Tempel.Variant
This type is the one will be consumed to Tempel.Local
This type is the retun after save from Tempel.Local
through Tempel.Persistence
Callbacks
This function is used to initialize the settings, could be storage path, aws secret key, etc.
Link to this section Types
This type is stuctured like the format of Plug.Upload
fileio()
is structured like file()
. But instead of the file path it contains the IO data in key :iodata
mainly the result from variant generation in Tempel.Variant
This type is the one will be consumed to Tempel.Local
This type is the retun after save from Tempel.Local
through Tempel.Persistence
Link to this section Callbacks
This function is used to initialize the settings, could be storage path, aws secret key, etc.
@callback pipeline(name :: atom(), files :: [file()], opts :: keyword()) :: raw_variant()