Compressing images before uploading to UploadThing?

Is there a way we can intercept the incoming upload request and, if they are images, compress them before they continue on to UploadThing?
7 Replies
feldrok
feldrok4mo ago
I would like to know this too
Christian Carpinelli
from what I understood about how the service works, right now, this is impossibile... Since the stuff that runs on our service is basically just the request to validate and get the upload url before starting the upload and a callback after the upload has finished. You can understand a lot more taking a look at this draw that Theo made:
No description
Christian Carpinelli
so... at least for now that we can't have additional stuff on top of the UT Ingest Server (which for what I'm guessing they'll charge more for additional services, like file compression and so on), what I'm doing is: - The user uploads a file. - UT triggers an "onUploadComplete" callback, in which I send a message to another microservice informing that a new file has been uploaded (with file reference that I got from the callback). - The service, will read this message with the file informations, retreive it and do compression on it, then upload the compressed file on UT again. If there's a more efficient way to do this currently using UT, please let me know.
Bumble
Bumble4mo ago
You can always do a normal upload using formdata (like in server actions) then upload the file from your server using the server API
Christian Carpinelli
oh yes of course, let's say that in that case (IMHO) you would loose a lot of the convenience of UT in comparison of a standard s3 bucket, or not?
Bumble
Bumble4mo ago
That's true. But if thinking about it, there has to be a tradeoff. In order to implement more features, you have to do more work.
Christian Carpinelli
Yeah, unfortunately, we can't have it all :poohheh:
Want results from more Discord servers?
Add your server