elixirdev

elixirdev

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:

Most Liked

Tricote

Tricote

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

Where Next?

Popular in Questions Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31013 112
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36352 110
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement