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
I would like to know this too
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:
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.
You can always do a normal upload using formdata (like in server actions) then upload the file from your server using the server API
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?
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.
Yeah, unfortunately, we can't have it all :poohheh: