View Source Bonfire.Files (Bonfire v0.9.10-classic-beta.156)
File management extension for Bonfire.
Bonfire Files wraps the Entrepot
a file management library,
adding support for media type checking, image resizing, and the like,
along with creating a pointable table for storage of file data.
Configuration
TODO's
- Generate docs
- More tests
This module contains general functions for handling files, and also an Ecto schema which is a multimixin for storing one or more media attached to a Pointable object.
An uploader definition must be provided for each upload, or will be automatically chosen based on the file type.
A few definitions exist as defaults inside of this namespace, but you can also define
your own - a Bonfire.Files.Definition
is an extension of Waffle.Definition
,
however the allowed_media_types/0
and max_file_size/0
callback are added,
with which you need to define what media types are accepted for these types of uploads.
(You can also return :all
to accept all media types).
To use the uploader:
iex> {:ok, media} = Bonfire.Files.upload(MyUploader, creator_or_context, %{path: "./150.png"})
iex> media.media_type
"image/png"
iex> Bonfire.Files.remote_url(MyUploader, media)
"/uploads/my/01F3AY6JV30G06BY4DR9BTW5EH"
Summary
Functions
Return the URL that a local file has.
Attempt to store a file, returning an upload, for any parent item that participates in the meta abstraction, providing the user/context of the upload.
Functions
Return the URL that a local file has.
upload(module, creator_or_context, file, attrs \\ %{}, opts \\ [])
View SourceAttempt to store a file, returning an upload, for any parent item that participates in the meta abstraction, providing the user/context of the upload.