enkr1
How to reorder the sequence of uploading files in `consume_uploaded_entries/3`
Hi community,
I am implementing a logic into my file uploader in which the first image of the selected list of images would have a special behaviour (in my case, it will be set as the thumbnail). However, I found out that the order of the uploaded images always flipped. For instance, filename, ["test_1.jpg", "test_2.jpg", "test_3.jpg"] will become ["test_3.jpg", "test_2.jpg", "test_1.jpg"].
My codes do not have much different from what you can find here Uploads — Phoenix LiveView v1.2.5, so I am curious if there is a way to set the order of the sequence in consume_uploaded_entries/3.
I don’t understand what is the sorting behaviour as I tried with different size, naming, it will always be flipped (descending)
Thanks in advance! ![]()
Marked As Solved
enkr1
I thought of a temporary solution:
Reversing the entries and reassign them back to the socket. From my understanding, consume_uploaded_entries/3 is a recursive function that is why the entry was flipped.
socket =
Map.put(
socket,
:assigns,
Map.put(
assigns,
:uploads,
Map.put(uploads, :medias, Map.put(medias, :entries, Enum.reverse(entries)))
)
)
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









