phoenixframework / phoenix_live_view

Rich, real-time user experiences with server-rendered HTML
https://hex.pm/packages/phoenix_live_view
MIT License
5.99k stars 902 forks source link

No way to cancel external upload #3287

Open balexand opened 1 month ago

balexand commented 1 month ago

Environment

Actual behavior

I'm doing video upload to Mux using the UpChunk library as described in https://hexdocs.pm/phoenix_live_view/uploads-external.html. I can cancel the upload by calling Phoenix.LiveView.cancel_upload/3. This clears the upload entry in the live view but it doesn't cancel the client-side upload. The upload continues to run and consume bandwidth until it completes or until the browser is refreshed.

Expected behavior

I would expect there to be a way to cancel an external upload in a way that stops the upload in the browser. This could be implemented as a callback in the external upload JS that would get called when the upload is cancelled. That callback could then call the abort function in UpChunk or in the XHR. The upload guide does something like this with the onViewError callback but this callback is only called when there is a view error, not when the upload is cancelled.