Problems with cancel_upload

I have a file upload implemented in the component. The upload works but when I try to cancel_upload I got an error.

[error] GenServer #PID<0.1663.0> terminating
** (MatchError) no match of right hand side value: nil
    (phoenix_live_view 0.17.5) lib/phoenix_live_view/upload.ex:73: Phoenix.LiveView.Upload.cancel_upload/3
    (neptune_web 0.1.0) lib/neptune_web/live/company/company_info_form_live.ex:153: NeptuneWeb.Company.CompanyInfoFormLive.handle_event/3
    (phoenix_live_view 0.17.5) lib/phoenix_live_view/channel.ex:349: anonymous fn/3 in Phoenix.LiveView.Channel.view_handle_event/3
    (telemetry 1.0.0) /Users/katarzyna/workspace/neptune_umbrella/deps/telemetry/src/telemetry.erl:293: :telemetry.span/3
    (phoenix_live_view 0.17.5) lib/phoenix_live_view/channel.ex:206: Phoenix.LiveView.Channel.handle_info/2
    (stdlib 3.16.1) gen_server.erl:695: :gen_server.try_dispatch/4
    (stdlib 3.16.1) gen_server.erl:771: :gen_server.handle_msg/6
    (stdlib 3.16.1) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

What can cause this error?
All event handlers are in the parent view. Checked the socket, and the assigned uploads look good.

1 Like

Hello and welcome,

The error should be around here (line 153)… can You show this code?

This is the line with cancel_upload function:

     |> cancel_upload(:logo, ref)
     |> assign(%{changeset: changeset, active_button?: false, show_logo_attachment?: false})}

I found the solution, I used the wrong ref. Not from entry but from uploads.logo.entry. Now it works :smiley:

1 Like