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 v0.20.2, 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)))
)
)







