matthieuchabert

matthieuchabert

Hey :waving_hand:

We use allow_upload/3 in an handle_event/3 function like so:

	  def handle_event("open_modal", params, socket) do
	  	socket = 
	      	socket
	          |> assign(:uploads, %{})
	          |> allow_upload(:image, [...])
	          [...]
	  
	  	{:noreply, socket}
	  end

It works fine when the event open_modal is triggered once but if it triggers again we get an issue:

(RuntimeError) existing upload for image already allowed in another component ()

This is raised by Phoenix.LiveView.Channel.ensure_unique_upload_name!/2 which checks if the upload name - here image - is unique.

In our case we can’t change that name to fix the issue and we’d like to reset that name unfortunately it isn’t stored in the socket assigns but in the Channel state which isn’t easily accessible from the Liveview.

Do you have any idea how we can solve this ?

Showing Posts 1 to 10

romenigld

romenigld

maybe with the handle_params function.

cblavier

cblavier

I don’t think handle_event is the culprit nor that handle_params would solve this.

I also faced this issue where I want to do mass input and submit the same form multiple times to create multiple entries and I could not find the way to properly reset the uploader. It’s like some lingering state is still existing in the LiveView process, despite reassigning :uploads or calling disallow_upload.

If someone has any clue, I would also be interested :person_shrugging:

trisolaran

trisolaran

Can you please explain a bit better what you’re trying to achieve? Why do you need to “reset” the upload? :thinking:

If I want to allow the user to submit multiple files with the same upload, I do that by setting auto_upload: true and handle all new uploads in the progress callback. Don’t know if this is related to what you guys want to do.

mcrumm

mcrumm

Phoenix Core Team

I can confirm– in short, you can invoke disallow_upload/2 after allow_upload/3 to disable uploading, but if you then invoke allow_upload/3 again with the same name we raise.

So at the moment there really is no way to “reset” a specific upload name, but I also can’t recall whether we intended this or not, so it might be a bug :slight_smile:

cblavier

cblavier

Thanks! Do you know who might recall?

mcrumm

mcrumm

Phoenix Core Team

Chris might remember– feel free to open an issue to get more feedback! :slight_smile:

matthieuchabert

matthieuchabert OP

We needed to “reset” the upload because the Liveview that handles the upload can invoke disallow_upload/2 and allow_upload/3 multiple times in a row (in handle_event/3 when a user opens/closes a modal). This isn’t the same thing as allowing multiple file upload.

As @mcrumm said:

We decided to put back allow_upload/3 in the mount/3 function and change dynamically the entry_path based on the socket assigns which is what we tried to achieve in the beginning.

It’s worth investigating anyway so we may open an issue :slight_smile:

Thanks for your help :pray:

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Is this a stateful or stateless component? I’m pretty sure that if you’re gonna have a component handle uploads the component needs to be stateful, and then with a unique ID in each case. This would avoid some of the issues I think?

EDIT: Specifically the idea in that case is that if you need to “reset” an upload you simply replace the whole component with a new instance of the stateful live component with a new unique ID

matthieuchabert

matthieuchabert OP

I edited my last answer for more clarity:

the upload because the Liveview that handles the upload can invoke disallow_upload/2 and allow_upload/3 multiple times in a row (in handle_event/3 when a user opens/closes a modal).

It’s a Liveview not a LiveComponent so no re-render :slight_smile:

hurricanebilly

hurricanebilly

The fix I went with was preserving the existing upload instead of recreating it – to the original poster, add a check to see if the upload is already created, and then don’t call allow_upload again if the upload already exists

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews