On server restart LiveView file upload form is not recovering auto

Hi everyone,
I am using LiveView file uploading which is working awesome. but when I deploy my server if someone uploading files, it stop uploading. So i am trying to use phx-auto-recover. When i restart server it try to recover last state of form. But due to different file upload reference facing this error.

Here is my code:

  @upload_options [
    accept: ~w(.jpg .jpeg .png image/jpeg image/png),
    max_entries: 5,
    max_file_size: 4857600,
    auto_upload: true
  ]

  def mount(_params, _session, socket) do
    {
      :ok,
     socket
     |> assign(:uploaded_files, [])
     |> allow_upload(:photo, @upload_options)
    }
  end

  @impl true
  def handle_event("recover_upload", params, socket) do
    IO.inspect params
    IO.inspect(socket)

    {:noreply, socket}
  end

  @impl true
  def handle_event("upload", _params, socket) do
    socket
    |> process_photos()

    {:noreply, socket}
  end

I am expecting it should execute recover_upload but it is not. it is throwing error before reaching to this function.

<form id="form" phx-submit="save" phx-change="upload" phx-auto-recover="recover_upload">
   <div class="file_upload">
      <%= live_file_input @uploads.photo %>
   </div>
</form>

Thanks in Advance :smiley:

Did you ever find a solution to this? I’m facing a similar thing that i feel should be possible when using external uploads

Old post but I faced a similar issue recently, so I wrote a summary of how I improved a little bit the situation with server restarts on forms containing file uploads :

Although the post doesn’t cover the case where the upload is not finished when the server restarts… it might be more complex to manage

Nicely written!

The technique with hidden input fields is useful in other contexts too. I once used it to maintain state on something like a multi-step form, turning the values of previous steps into hidden fields for recovery.

Maybe the technique deserves a mention in the official auto-recovery docs!

I found this very useful for implementing recovery of uploaded files – thank you!

Did you manage to tackle recovery of pending/in-flight uploads on reconnect?