Hello!
I am trying to get file uploads to work in liveview and i think im getting pretty close, however, as this is my first time working with elixir i am getting stuck on a error message that i cant really interpret from the output.
This is my definition that i use in a HEEX file with no paramteters, can i not do this?:
defp has_uploaded_entries() do
not Enum.empty?(uploaded_entries(@socket, @upload_ref))
end
Socket should be assigned internally in the mount definition from what im understanding? Is my @upload_ref definition whats causing the issue?:
@upload_ref :uploads
def mount(_params, _session, socket) do
File.mkdir_p!(@upload_dir)
{:ok,
socket
|> assign(:uploads_in_progress, [])
|> assign(:uploaded_files, [])
|> allow_upload(@upload_ref, max_entries: 5, auto_upload: false, accept: :any)}
end
This is the error i am getting:
no function clause matching in Phoenix.LiveView.Upload.uploaded_entries/2
Called with 2 arguments --
1. nil
2. :uploads
Why would socket be nil in this case? Isnt the socket connected and alive before the JS is fully loaded? I'll send the HEEX code below just so that i dont leave anything out:
<div class="mt-8">
<.progress_display entries={@uploads_in_progress} />
<%= if has_uploaded_entries() do %>
<button phx-click="complete_upload" class="mt-4 w-full bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-3 px-4 rounded-lg shadow transition duration-150">
Finalize Uploads
</button>
<% end %>
<.file_list files={@uploaded_files} />
</div>
Any help is appreciated as i really like elixir so far, it just feels so smooth coming from c#, c and python before.