marschro

marschro

LiveView File Upload - Flush errors and reset

Hi everyone,

I have implemented a file upload with live view.
I follow pretty much the basics, except of having a custom upload-writer.

What I figured out is the following:

  1. When having a live_file_input
  2. And set allow_upload with max_entries: 2
  3. Then, uploading two files successfully
  4. And then, being within the same LiveView, adding again a file to the upload
  5. Then the error comes up: :too_many_files - so even when the max files of two just were uploaded successfully, the next upload is counted as third file…

This should not be the case. Somehow, after every successful upload, the entries are not cleared or the errors not flushed.

This prevents from consecutive uploads.

In order to solve that, the live-view has to be re-mounted (reloaded) then the upload works again.

There is the option to disallow_upload/2 - but that does not work (tried to disallow and re-allow again)

What I miss, is the option that the upload is re-initialized when all uploads are done, or manually to reset or re-init the upload after all went successfully.

Can everyone reproduce that or did I something wrong?
Any hint appreciated.

Cheers,
Martin

Marked As Solved

marschro

marschro

If anyone ever runs into that problem, you probably haven’t implemented consume_upload_entries/3 in your lv.

It’s not obvious as long if you do not read the documentation carefully, where everything is totally fine explained.

Consumes the uploaded entries.
Raises when there are still entries in progress. Typically called when submitting a form to handle the uploaded entries alongside the form data. For form submissions, it is guaranteed that all entries have completed before the submit event is invoked. Once entries are consumed, they are removed from the upload.

You need to invoke that function to clean up the uploaded entries… this function incorporates the flushing and clean up and everything.

have fun… there is always a solution to everything… :smiley:

Where Next?

Popular in Questions Top

New
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
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
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
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
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
dotdotdotPaul
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
New

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29377 241
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
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
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 47930 226
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New

We're in Beta

About us Mission Statement