smon
I am experimenting with live view uploads for the first time, and I was wondering what is the recommended way of doing customized upload validations.
My simple example: I have an interface to upload files to a certain directory, and I want to warn the users of duplicate file names in their upload before they hit the submit button. My consume_uploaded_entries/3 would catch these cases, but I am expecting larger files being uploaded, so some feedback earlier would be nice.
So I could evaluate my uploads assign against a list of existing files by…
… setting :valid to false in the appropriate Phoenix.LiveView.UploadEntry structs.
… generating an appropriate error list for errors in the Phoenix.LiveView.UploadConfig struct.
It feels a little bit like screwing around with Phoenix LiveView implementation internals. Is this the way to do it? Did I miss some kind of helper function?
Trending in Questions
Other Trending 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
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
smon
I tried to implement my own entry validation, as described above, by extending the
handle_info/3that reacts to form changes.See Uploads — Phoenix LiveView v1.2.5
But now I bumped into the issue: After evaluating the affected entries and setting appropriate errors, I am not allowed to use re-
assign/3the:uploadkey because it is a “reserved” one:So my initial reaction proved somewhat right: The LiveView authors do not want me to prod around in those internals.
But: What can I do now? What seems to be missing is an option for
allow_uploads/3for passing a custom validator function.smon
Ok, I got it working by not using
assign/3which is a bit frightening. For anyone daring enough, here is the implementation.My customized
handle_event/3looks like this.Here
existing_filesis a list containing application specific metadata structs. As you can see I useMap.put/3to hack my way around the “reserved assign” restriction.The function
mark_duplicate_names/2looks like this:Finally I implement a fourth
error_to_string/1function:smon
Small update: In order to preserve the errors that got returned by Phoenix’ standard evaluation (size, type, upload count issues), I had to modify the function slightly.