While Phoenix LiveView handles many aspects of file uploads elegantly, managing server restarts and deploys on forms with uploads is not completely handled by default. The auto-recovery mechanism works well for regular form fields so that if a server restart occurs while a user is filling out a form, all the standard fields are recovered automatically. However, file uploads are not.
In this post, I’ll walk through a robust approach to managing file uploads in LiveView that survive server restarts and provide a seamless user experience.
We’ll build a blog post system with document uploads using a step-by-step approach. Each
Post
can have multiple associatedDocument
files that users can upload through both “new” and “edit” forms. Starting with basic upload functionality, we’ll progressively add auto-recovery and cleanup mechanisms.Note that we’ll use the
Waffle
andWaffle.Ecto
libraries to handle file uploads.
continue reading on plain-old-elixir-modules.com
⚠️ This post links to an external website. ⚠️
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.