ken-kost

ken-kost

I have a modal with form and live image upload which uploads selected image on form submit. Also on the form a button for submodal can appear which opens another modal on top of form modal and after closing it you get back to the form. All the changes will remain, except for the image preview which is not in changeset but in uploads.

What I want is the selected image preview remains after submodal close. One of my attempts was to store the entry in changeset i put it back on load/change, which worked but it did not solve my issue.

So I dug deeper and as far as I understand, when I call live_img_preview which calls content_tag with data_phx_entry_ref which is used deep in the javascript live_uploader.js

static getEntryDataURL(inputEl, ref, callback){
    let file = this.activeFiles(inputEl).find(file => this.genFileRef(file) === ref)
    callback(URL.createObjectURL(file))
  }

And then I get the error

Uncaught TypeError: URL.createObjectURL: Argument 1 is not valid for any of the 1-argument overloads.
    getEntryDataURL live_uploader.js:28
    mounted hooks.js:36
    __mounted view_hook.js:17
    performPatch view.js:341
    trackAfter dom_patch.js:59
    trackAfter dom_patch.js:59
    perform dom_patch.js:191
    perform dom_patch.js:191
    performPatch view.js:362
    update view.js:451
    time live_socket.js:208
    update view.js:448
    applyPendingUpdates view.js:503
    applyPendingUpdates view.js:503
    pushLinkPatch view.js:964
    pushWithReply view.js:636
    matchReceive push.js:76
    matchReceive push.js:76
    startTimeout push.js:107
    trigger channel.js:278
    Channel channel.js:70
    trigger channel.js:278
    onConnMessage socket.js:510
    decode serializer.js:25
    onConnMessage socket.js:497
    onmessage socket.js:221
    connect socket.js:221
    doConnect live_socket.js:191
    connect live_socket.js:195
    <anonymous> app.js:46
    <anonymous> app.js:4396
live_uploader.js:28:17
    getEntryDataURL live_uploader.js:28
    mounted hooks.js:36
    __mounted view_hook.js:17
    performPatch view.js:341
    trackAfter dom_patch.js:59
    forEach self-hosted:164
    trackAfter dom_patch.js:59
    perform dom_patch.js:191
    forEach self-hosted:164
    perform dom_patch.js:191
    performPatch view.js:362
    update view.js:451
    time live_socket.js:208
    update view.js:448
    applyPendingUpdates view.js:503
    forEach self-hosted:164
    applyPendingUpdates view.js:503
    pushLinkPatch view.js:964
    pushWithReply view.js:636
    matchReceive push.js:76
    forEach self-hosted:164
    matchReceive push.js:76
    startTimeout push.js:107
    trigger channel.js:278
    Channel channel.js:70
    trigger channel.js:278
    onConnMessage socket.js:510
    decode serializer.js:25
    decode self-hosted:1151
    onConnMessage socket.js:497
    onmessage socket.js:221
    (Async: EventHandlerNonNull)
    connect socket.js:221
    doConnect live_socket.js:191
    connect live_socket.js:195
    <anonymous> app.js:46
    <anonymous> app.js:4396

I googled the error, one response is

that createObjectUrl is deprecated.

window.URL.createObjectURL(file) Replace with window.URL.srcObject = file

But I’m not sure if that’s the issue, or that the file disappears after changing modal/route.

phoenix liveview

Showing Posts 1 to 3

LostKobrakai

LostKobrakai

For uploads LV maintains a lot more state than you get to interact with (including tmp files and such). Therefore you cannot just set values back like with a changeset. If those entries are to be maintained you want to go for a strategy where LV never get’s rid of those entries in the first place. That might be possible by patching between modals and keeping the upload allowed on both, but I’m not sure about that.

i-n-g-m-a-r

i-n-g-m-a-r

Did you find a solution?

This thing does not fail nicely.

Screenshot from 2023-12-21 09-10-40

Maybe there’s some way to clean up previews?
Or maybe file should be validated before calling URL.createObjectURL

i-n-g-m-a-r

i-n-g-m-a-r

This works for me.

def upload_names, do: [:name_a, :name_b, :etc]

def cleanup_previews(socket) do
  Enum.reduce upload_names(), socket, fn n, s ->
    {_completed, in_progress} = uploaded_entries(s, n)

    Enum.reduce in_progress, s, fn e, s ->
      cancel_upload(s, n, e.ref)
    end
  end
end

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
nseaSeb
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
kpanic
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
velrest
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
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
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
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
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews