pingdotgg / uploadthing

File uploads for modern web devs
https://uploadthing.com
MIT License
3.74k stars 267 forks source link

feat: Docs on how to compress / resize an image on the server before upload #807

Closed JRichens closed 1 month ago

JRichens commented 2 months ago

Describe the feature you'd like to request

api/uploadthing/core.ts

// FileRouter for your app, can contain multiple FileRoutes export const ourFileRouter = { // Define as many FileRoutes as you like, each with a unique routeSlug imageUploader: f({ image: { maxFileSize: "8MB" } }) // Set permissions and file types for this FileRoute .middleware(async ({ req }) => { // This code runs on your server before upload const user = await auth(req) // explain here

Explain here how to compress an image and resize it before uploading

Describe the solution you'd like to see

Add to the documentation suggested ways of compressing / resizing

Additional information

No response

๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ฆ Contributing

juliusmarminge commented 2 months ago

well the short answer is you can't, cause for client-side uploads the file never hits your server. your server is only used to request presigned urls in a secure manner. so if you wanna preprocess the file, you'd do that on the client, for example in the onBeforeUploadBegin callback

if you wanna do this, you'd need to use server-side uploads. Submit the file to your server, do your thing and use utapi.uploadFiles to upload the compressed image.

github-actions[bot] commented 1 month ago

This issue has been automatically marked as stale because it has not had any activity for 10 days. It will be closed in 5 days if no further activity occurs.

github-actions[bot] commented 1 month ago

This issue has been closed because it has not had any activity for 5 days since being marked as stale.