PrincetonPoh
I’m trying to upload a music file. I’ve created a music struct. It takes a title (string) and file_path (string)
I create a form which requires a title and a file upload.
What I expect is for the form to throw errors when 1) the upload is empty or 2) the title is empty.
The problem:
Case 1: title and file are empty. Only the error “empty title” is shown. NO ERROR for missing upload is shown
Case 2: there’s file input but no title. When I press the upload button, presign_upload() is called and the file is sent to the cloud even though my title is empty.
Both cases are not idea. This seems like a pretty basic use case. Am I missing something?
It appears that this guy was trying to implement it too but failed in the end.
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
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
- #elixirconf-us
- #blog-post
- #ai
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
LostKobrakai
I’d strongly suggest you don’t depend on a file only being uploaded if the form is valid. There’s simply no solution to atomically persist data in the db and have an upload persisted in a different system, so pretending it would work like that is not going to be great.
The workflow I generally suggest is uploading to a temp. directory, which is regularly cleaned up (e.g. S3 can do so with livecycle configuration). Then persist the data in the db pointing to the temporary file and within the same transaction queue work (e.g. using oban) to move the file to a different path, where it won’t be deleted. That way you don’t need to care if the upload happened a few seconds or minutes before the form was submitted.
However the issue around changeset errors being a completely separate system to the errors shown for LV uploads is indeed problematic. I’ve been running into that myself as well.
PrincetonPoh
Thank you for this. It’s helpful for me to conceptualise this at a more fundamental level.
Oh wow, is this the industry standard to basically set up a “routine clean up” system?
How have you dealt with it? I think solving this issue will at least reduce the chances of redundant uploads to S3.
LostKobrakai
Yes – unless you’re storing the uploaded files in db or your stored files are all the data to be stored (no related records elsewhere). Everything else is essentially a distributed system with all their (lack of) guarantees.
I didn’t have the need. It wasn’t for anything in production. In software I use I often see file uploads completely separate from form submission, where entries can be created completely separate from any files they might relate to, while those files are independently attached later.
PrincetonPoh
Ok, thank you for your help!
For anyone else reading, I tried to solve the Case 2 problem above with a simple case do in my presign_upload(). It was a failure as i need to surgically manipulate the socket to edit the errors so that the usual handle events can validate my forms. I shall await a more skilful individual to navigate this :')
romenigld
Hello I posted here the way I did that was:
“I used only the changeset and get the field with
get_field/2and if is empty photos the:photo_urlsfield you can insert an error with the functionadd_error/3and all of that is a function calledvalidate_empty_photo_urls”.It is ok with that @LostKobrakai or prefer to do other thing?
krishandley
My solution to work around this is having two forms.
A normal form with a quick hack to trigger the live_file_input
And a second form with the uploads in to submit manually after the normal form has been saved