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 ![]()
Most Liked
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
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance










