Next.js Discord

Discord Forum

Compress Image while uploading to server

Unanswered
Chukar posted this in #help-forum
Open in Discord
ChukarOP
In my next.js web app, I want to upload local images to server but want to first compress them like converting them into avif format just before uploading to server. Is there any way to do this?

16 Replies

You should do compressing stuff on server, not on Next.js
ChukarOP
I want to do on browser side not on server side.
I believe it is better if you do it in server side, it has better tools. But you can find some resources for converting them on webiste ig. for ex: https://labs.madisoft.it/javascript-image-compression-and-resizing/
ChukarOP
I am trying to use WASM-ImageMagick but there are issues in that
no idea what that is
last published 4 years ago
Why are you persistent to use it on browser tho?
ChukarOP
As I don't want to send heavy image files to server and then compress them. Instead I want to send already compressed image to server.
okay, upto you
I don't see any good tools to compress in browser
and server is supposed to do heavy things
so I don't understand what you are trying to accomplish
@Chukar I want to do on browser side not on server side.
Toyger
you can't do that on browser side, but you can do that on your machine, write script that you'll run either in production build either manually, and compress images, then upload to git and vercel will get it from there, but you need to use <img> instead <Image> or add unoptimized attribute so vercel ignore them for optimization.
ChukarOP
I don't want to do that in my machine
@Chukar I don't want to do that in my machine
Toyger
you basically said
Instead I want to send already compressed image to server.
how do you want to send them already compressed to server if you don't want compress them anywhere before they get to server?
he want it on client side's browser apparently