soullpoint
Hi, please forgive me if I am missing something obvious, I am relatively new to Elixir and Phoenix.
I am wondering if there isn official way of handling errors, e.g. cancelling failed uploads.
I am following the example in the official guide: https://hexdocs.pm/phoenix_live_view/uploads-external.html#direct-to-s3
From what I can gather, there is a list of entries for the uploading files @uploads.file.entries, and a list of errors @uploads.file.errors that is populated when an error occurs, but there isn’t really a connection between the two apart from them sharing the “ref”.
I’m finding that I have to do something like this:
<%= for entry <- @uploads.file.entries do %>
<%= entry.client_name %> - <%= entry.progress %>%
<%= if @uploads.file.errors |> Enum.into(%{}) |> Map.has_key?(entry.ref) do %>
<span phx-click="clear-failed-upload" phx-value-ref="<%= entry.ref %>">Clear</span>
<% end %>
<% end %>
I’m rather new to Phoenix, so I don’t really have a frame of reference to know if this is a typical pattern, but my initial reaction is that this seems a bit contrived for what I would image is a common use case.
Would anyone be able to shed some light on this?
Thanks
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex











Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
mcrumm
Hi @soulpoint! You can use
upload_errors/2to get the error for a specific upload entry - here’s an example from the docs:In your example, if you only want to show the Clear link on error, you could do something like this:
soullpoint
I didn’t realise that function existed, that’s awesome!
Thanks @mcrumm!