nallwhy

nallwhy

In the current implementation of Phoenix.LiveView.Upload, when you configure external: &function/2, it becomes mandatory to specify an uploader.

This makes sense in most cases, but there’s an important limitation: Once you introduce even a single external uploader, you lose the ability to fall back to the default built-in uploader.

This can be problematic when you want to mix different uploader strategies depending on the file — for instance, using a custom external uploader for images, but sticking to the built-in uploader for PDFs or other files.

I’ve patched LiveView locally to support falling back to the default uploader even when external: &function/2 is set — and it works well in my testing.

defmodule MyApp.SampleLive do
  ...
  def mount(_, _, socket) do
    socket =
      socket
      |> allow_upload(:files, external: &presign_upload/2)

    {:ok, socket}
  end

  defp presign_upload(entry, socket) do
    meta =
      case entry.client_type do
        "image/" <> _ -> %{uploader: "S3", presigned_url: "..."}
        _ -> nil
      end

    {:ok, meta, socket}
  end
end

If simply returning nil for the uploader in meta seems inappropriate, alternatives like %{uploader: nil} or %{uploader: :default} could be used instead.

If this sounds like a reasonable enhancement, I’d be happy to polish the implementation and open a PR. I think this could make LiveView uploads more flexible without breaking existing behavior.

Where Next? Top

Trending in Proposals: Ideas Top

woylie
We are seeing a lot of warning logs like this: navigate event to "https://someurl" failed because you are redirecting across live_sessio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews