Get image size using UploadThing
Hey all, trying to get the image size of a file when a client uploads. Any recommendations?
I'm thinking it could be done client size, before the file gets uploaded then meta info passed to uploadthing. Not sure how to do this 'before' the upload when using the UploadThing API. Theres
onUploadProgress
onClientUploadComplete
and onUploadError
, but no sort of preflight callback where I can read the file's buffer.
Another option could be server side, once the file is uploaded, call a server function which gets passed the uploadthing url and does a HTTP get to work out the size.
The aim is to have the file size in a metadata object that goes along with the url when it's added to a database.
So yeah, how can I grab the file buffer before uploading? Thanks!1 Reply
OK this repo is a good example, will study this later https://github.com/pingdotgg/uploadthing/blob/main/examples/appdir/src/app/image-crop/image-cropper.tsx
GitHub
uploadthing/examples/appdir/src/app/image-crop/image-cropper.tsx at...
File uploads for modern web devs. Contribute to pingdotgg/uploadthing development by creating an account on GitHub.