LiveView File UploadConfig entries attribute is an empty list

I am using Phoenix Live Uploads for the first time. Inspecting @uploads.photo shows entries attribute to be an empty list even after uploading a file.

{:ok,
      socket
       |> assign(:user, user)
       |> assign(:token, token)
       |> allow_upload(:photo, accept: ~w(.png .jpeg .jpg), max_entries: 1, max_file_size: 500_000,)

this is the form I am rendering for the upload

<%= form_for @changeset, "#", phx_submit: "save"  %>
  <ul class="list">
      <%= inspect(@uploads.photo) %>
      <%= live_file_input @uploads.photo %>
  </ul>
  <div class="toolbar__center" style="width: 100%; padding-right: 14px; padding-left: 14px; padding-top: 8px; padding-bottom: 8px;">
    <%= submit "Upload", phx_disable_with: "Uploading..." %>
  </div>
</form>

this is the result of inspecting @uploads.photo after adding an image to upload

#Phoenix.LiveView.UploadConfig< accept: ".jpg,.jpeg,.png", auto_upload?: false, entries: [], errors: [], max_entries: 1, max_file_size: 500000, name: :photo, progress_event: nil, ref: "phx-Fpf-qu5HLEM4zwth", ... >

What might I be missing

I have not taken care of the “save” event yet. Just wanted to confirm each step of the way but let me handle those 2 events for that reason. Thank you

Hi @Muhammad-Mullah – you will need to configure a phx-change event for your form containing the live_file_input. Otherwise, without the change event, the files will never be pre-flighted to the server.

3 Likes