Storage.LiveView (PhoenixContribStorage v0.1.0)
View SourcePhoenix LiveView helpers for file uploads.
Summary
Functions
Consumes uploaded entries for a has_many_attached relationship.
Consumes uploaded entries and creates Storage blobs.
Default progress handler for uploads.
Helper for generating file upload configuration.
Functions
Consumes uploaded entries for a has_many_attached relationship.
Examples
def handle_event("save", %{"post" => post_params}, socket) do
images =
consume_uploaded_entries(socket, :images, fn %{path: path}, entry ->
{:ok, Storage.LiveView.consume_uploaded_entry(path, entry)}
end)
Storage.Attachment.attach_many(post, :images, images)
end
Consumes uploaded entries and creates Storage blobs.
Examples
def handle_event("save", %{"user" => user_params}, socket) do
uploaded_files =
consume_uploaded_entries(socket, :avatar, fn %{path: path}, entry ->
{:ok, Storage.LiveView.consume_uploaded_entry(path, entry)}
end)
# Use uploaded_files with your changeset...
end
Default progress handler for uploads.
Helper for generating file upload configuration.
Examples
def mount(_params, _session, socket) do
socket =
socket
|> allow_upload(:images, Storage.LiveView.upload_options(
accept: ~w(.jpg .jpeg .png),
max_entries: 5,
max_file_size: 5_000_000
))
{:ok, socket}
end