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

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
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
samoloth
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
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
psy-q
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
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
marciok
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
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 & Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews