Teslim
Hi, please help me. After generating presigned_url from presigned_upload, I am expecting handle_event(“save”) to be called, but it is not fire. Kindly help me; I don’t know what I am doing wrong.
@impl true
def render(assigns) do
~H"""
<div>
<.header>
<%= @title %>
<:subtitle>Add new project to database.</:subtitle>
</.header>
<.simple_form
:let={f}
for={@changeset}
id="project-form"
phx-target={@myself}
phx-change="validate"
phx-submit="save"
>
<.input field={{f, :title}} type="text" label="Title" />
<.input field={{f, :description}} type="text" label="Description" />
<.input field={{f, :active}} type="checkbox" label="Active" />
<.live_file_input upload={@uploads.images} />
<div class="bg-gray-100 p-6" phx-drop-target="{@uploads.images.ref}">
<%= for {_ref, err} <- @uploads.images.errors do %>
<p class="alert alert-danger"><%= Phoenix.Naming.humanize(err) %></p>
<% end %>
<div class="grid grid-cols-2 gap-4">
<%= for entry <- @uploads.images.entries do %>
<div class="flex items-center space-x-4 p-4">
<.live_img_preview entry={entry} width: 5 />
<div>
<div>
<p class="text-xl"><%= entry.client_name %></p>
</div>
</div>
</div>
<% end %>
</div>
</div>
<:actions>
<.button phx-disable-with="Saving...">Save Project</.button>
</:actions>
</.simple_form>
</div>
"""
end
@impl true
def update(%{project: project} = assigns, socket) do
changeset = Projects.change_project(project)
{:ok,
socket
|> assign(assigns)
|> assign(:changeset, changeset)
|> assign(:uploaded_files, [])
|> allow_upload(:images,
accept: ~w(.jpg .jpeg .png),
max_entries: 5,
# max_file_size: 50_000,
external: &presigned_upload/2
)}
end
defp presigned_upload(entry, socket) do
bucket = "tes-portfolio"
key = "public/#{entry.client_name}"
{:ok, presigned_url} = ExAws.Config.new(:s3) |> ExAws.S3.presigned_url(:put, bucket, key)
meta = %{uploader: "S3", bucket: bucket, key: key, url: presigned_url}
{:ok, meta, socket}
end
@impl true
def handle_event("cancel-upload", %{"ref" => ref}, socket) do
{:noreply, cancel_upload(socket, :images, ref)}
end
@impl true
def handle_event("validate", %{"project" => project_params}, socket) do
changeset =
socket.assigns.project
|> Projects.change_project(project_params)
|> Map.put(:action, :validate)
{:noreply, assign(socket, :changeset, changeset)}
end
def handle_event("save", %{"project" => project_params}, socket) do
uploaded_files =
consume_uploaded_entries(socket, :images, fn %{} = meta, _entry ->
{:ok, presigned_url} =
ExAws.Config.new(:s3)
|> ExAws.S3.presigned_url(:get, meta.bucket, meta.key, expires_in: 86_400)
presigned_url
end) |> IO.inspect
save_project(socket, socket.assigns.action, project_params)
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,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
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
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
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
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
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
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
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
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
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
mcrumm
If you want uploads to happen automatically, without a form submit, you need to add
auto_upload: trueto your upload config and then consume uploads in a custom progress callback, as in the docs example:Teslim
Thank you @mcrumm for your response.
Normally, what I want is to submit the form and upload it. but when I submit nothing happens I only get the
presigned_urlandhandle_event("save")is not fire which is why am confused.I have updated my snippet to reflect render function
mcrumm
At a glance your template looks fine. Are you getting any errors in the browser console?
Teslim
I got this from the browser, Do I need to do another setup aside from what I have done above
mcrumm
Yes you need the client-side
Uploaders.S3code from the External Uploads guideTeslim
Thank you @mcrumm everything is working fine now, I will update the full working script