artem

artem

Hi all

Context
I am making a small voice note sharing service in LiveView: record a voice note in the web page, it gets uploaded to S3 and then LiveView provides a player page that could be shared to twitter with nice and interactive look.

I managed to record mp3 audio with pretty cool visualization (right now could be seen at https://voicepen.fly.dev/ ) as just a blob, can generate a file-like object via URL.createObjectURL(mp3Blob) and I am trying to upload it to S3 via external uploads (why to pass file through the server side if I need just a link to the final object on S3) and.. I can’t figure how to do it :slight_smile:

External uploads
LiveView has great external uploaders that work just fine with real file inputs, but how could I use them with something generated dynamically in javascript?

My understanding is that in JavaScripts it is not easy (maybe even not possible in older browsers) to replace real file input with dynamic objects, but external uploads are anyway going through the JavaScript-side HTTP requests. I’d just like to piggy back on LiveView mechanics for easy error reporting, progress information, consume_uploaded_entries in handle_event.

Options
I can see several options of possible research and would appreciate comments on which of these could be more promising. Hopefully somebody has done something similar or possibly have contributed to implementing support for external uploads :slight_smile:

Option A: Try replacing or adding a file input to the existing LiveView form with external uploads

// something like this:
const formElement = document.forms.namedItem("upload-form");
const formData = new FormData(formElement);
formData.append("audio_file", mp3Blob);

Option B: Dive into JavaScript side of LiveView uploaders and plug into them
I.e. study live_uploader.js, upload_entry.js in LiveView source code and inject my file-like object via it.

Option C: Talk to server side instead of LiveUploaders
Study same live_uploader.js and related files, figure which messages they send to live socket and do the same.. essentially replicating these, maybe it’s simpler than it sounds

Option D: Forget the whole thing as too complex and just do client-side upload
The biggest reason to go via external liveview uploads for me is my not too high knowledge of the whole Phoenix (I am new to elixir), so by utilizing standard(ish) mechanisms I hope to avoid the unexpected issues and get standard benefits (standard callbacks, error messaging, progress indicators), but maybe it’s not worth the effort needed for workaround.

Option E: Something very different
Do I miss something else that could be much similar

What would you do? I’ll appreciate any advice and pointers to where to look further.

Showing Posts 1 to 2

mcrumm

mcrumm

Phoenix Core Team

You can use the upload() method on a client-side hook to enqueue a File-like object to a live_file_upload. This works for external uploads to S3 as well. Here is an example hook:

https://github.com/mcrumm/live_upload_example/blob/main/assets/js/media_recorder_demo.js

…and its corresponding LiveView example:

https://github.com/mcrumm/live_upload_example/blob/main/lib/drops_web/live/uploads_live/media_recorder.ex

artem

artem OP

Ah, I didn’t realize there’s an upload() method available to the hook! It worked, thank you!

— 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
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
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
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
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
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