Book: Programming Phoenix LiveView, page 142 (157/378), file lib/pento_web/live/product_live/form_component.ex, in the function below:
defp handle_progress(:image, entry, socket) do
:timer.sleep(200)
if entry.done? do
# here instead of {:ok, path} I changed to path only, and it worked
path =
consume_uploaded_entry(
socket,
entry,
&upload_static_file(&1, socket)
)
{:noreply,
socket
|> put_flash(:info, "file #{entry.client_name} uploaded")
|> assign(:image_upload, path)}
else
{:noreply, socket}
end
end
Let me know if this is correct, because here It only worked when I changed.
I ran into this too. It looks like the function Phoenix.LiveView.Upload.consume_entries has been changed to return just the results in LiveView 0.17.9.
We’ll correct this in the next release, but in the meantime–the upload_image_error/2 function is a helper function defined in the form component module. You can add it like this:
# lib/pento_web/product_live/form_component.html.heex
def upload_image_error(%{image: %{errors: errors}}, entry) when length(errors) > 0 do
{_, msg} =
Enum.find(errors, fn {ref, _} ->
ref == entry.ref || ref == entry.upload_ref
end)
upload_error_msg(msg)
end
def upload_image_error(_, _), do: ""
defp upload_error_msg(:not_accepted) do
"Invalid file type"
end
defp upload_error_msg(:too_many_files) do
"Too many files"
end
defp upload_error_msg(:too_large) do
"File exceeds max size"
end
For the issues that are being described re: the flash message and filename–we’ll dig into these further as we prepare for a non-trivial code upgrade for the latest versions of LiveView once 0.18 is released in the coming weeks and months. Stay tuned for updates in the meantime I recommend moving on to the next chapters.
Hey @SophieDeBenedetto, I know you’ve mentioned recently that you will be doing an update to the book once LiveView hits 1.0. With your comment above about v0.18, are you planning on updating the code earlier since v0.18 introduced some significant changes?