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

Link to this function

ap_publish_activity(medias)

View Source
Link to this function

ap_receive_attachments(creator, attachments)

View Source
Link to this function

data_url(content, mime_type)

View Source
Link to this function

delete_files(module \\ nil, media, opts \\ [])

View Source
Link to this function

file_extension_only(path)

View Source
Link to this function

full_url(module, media, version \\ nil)

View Source
Link to this function

get(struct, key, default \\ nil)

View Source
Link to this function

local_path(module \\ nil, media, version \\ :default)

View Source
Link to this function

normalise_size(size, default \\ 8)

View Source
Link to this function

remote_url(module \\ nil, media, version \\ :default)

View Source

Return the URL that a local file has.

Link to this function

upload(module, creator_or_context, file, attrs \\ %{}, opts \\ [])

View Source

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.

Link to this function

validate(other, allowed_media_types, max_file_size)

View Source