Programming Phoenix LiveView: Live Upload Match Error

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