Created
July 23, 2021 10:35
-
-
Save fantypants/1fc5b1030c90bad0d7392e5d58a0f869 to your computer and use it in GitHub Desktop.
UploadChannel triggers arg error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule ModuleWeb.ImportLive do | |
use Phoenix.LiveView | |
require Logger | |
import Ecto.Query | |
def mount(_params, _session, socket) do | |
{:ok, | |
socket | |
|> assign(:uploaded_files, []) | |
|> allow_upload(:templates_file, accept: ~w(.json), max_entries: 1, auto_upload: true)} | |
end | |
def handle_event("validate-imports", params, socket) do | |
{:noreply, socket} | |
end | |
def handle_event("save-imports", params, socket) do | |
uploaded_files = | |
consume_uploaded_entries(socket, :templates_file, fn %{path: path}, entry -> | |
Logger.warn "File!!" | |
end) | |
{:noreply, socket} | |
end | |
def render(assigns) do | |
~L""" | |
<form id="import-form" phx-submit="save-imports" phx-change="validate-imports" class="form"> | |
<%= live_file_input @uploads.templates_file %> | |
<button type="submit">Upload Template File</button> | |
</form> | |
""" | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment