derek-zhou
Liveview’s upload is simple enough to use. However, I now have a need to modify the file content before the upload. Specifically, I want to scale down the image at the client side before sending the potentially very large file over the network. Is there any javascript hook that enable me to do that?
Trending in Questions
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
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
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
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
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
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
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
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
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
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
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
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
sreyansjain
Did you find a way to do it?
regex.sh
You can achieve that with custom client side JS, before submitting you have files available for manipulation.
Usefull links: LiveView Upload docs
sreyansjain
Sorry I am not able to figure that out. How to do it? By using Hooks?
Where are the files stored? Would be very grateful if you can share some code sample.
Thanks.
regex.sh
I’m not sure what your use case is, but you can send events back and forward to preform some actions.
Here you can find example code for uploading files, and you can put some logic in
validateto send client side some data or w/e you need and then handle push event on client and preform action on images or something else.sreyansjain
Thank You for the input.
I just want to downsize large images.
I can send events and recieve them on the client.
But I am not sure where the files are located that I need to modify.
I am thinking that for external uploaders live view provides a Uploader with entries. That might be a place to modify the files.
polypush135
I was just sharing with someone about this yesterday.
In short, yeah everything is done client side via hooks.
In one example I load an image with a wasm lib via a canvas on the dom, that is used to resize.
The other, I upload file to a bucket, call third party scale api with bucket path, download scaled image back to clients re-upload with new signed url.
Edit: I should add its easy to overload the browser in the case of the canvas/wasm workflow.
On a phone loading several 24mb sized images in to canvas has been able to crash a mobile browser really fast and given the size of raw phone images now it was a common issue I seen. The better of the two approaches I found was to use a signed url to throw the image at a buck then trigger a worker to async resize the image and fetch it later and or move it from a temp bucket to a permanent place. Uploading large files to a bucket is a non issue and its was better to have a back up of the source upload in my case too. I also found minio for self hosting buckets which made going the object store approach a lot for effective for me. That said I would love it if there was a really good full client side solution to this. Y
derek-zhou
Yes, I scale the image using client side js and store the result in a blob. Then I chunk the blob, basse64 encode them, and send the chunks in-band in with
pushEventSee here for the js part:
https://github.com/derek-zhou/gara/blob/main/lib/gara_web/components/header.hooks.js
mcrumm
To be clear, you have to do all these extra steps because you want to modify the file client-side and then upload it to your webserver and not to cloud storage, correct?
I wonder if LiveView should support a client-side callback for server uploads
derek-zhou
Yes. My way does not make the best use of the bandwidth, and it is streaming binary data from browser memory to server memory, so it won’t work for large files. On the other hand, it is fairly simple and there is no need to cleanup should the user navigate away.
The only thing I wish from Liveview is the support for binary messages without resorting to base64. I could use a raw socket but then I need to deal with coordination between 2 processes.
sreyansjain
That would be very welcome. Especially for common use cases like resizing images before uploading (especially on mobile devices).