#Is it possible to optimize images as they are uploaded?
3 messages · Page 1 of 1 (latest)
Hi @frank yacht. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Yes, it's possible to optimize images as they're uploaded to Convex to save space, though Convex doesn't provide built-in image optimization. You'll need to implement this yourself using Node.js libraries in an action function.
Based on community discussions, there are a few approaches:
-
You can use image processing libraries like Sharp in a Node.js action. One community member mentioned successfully using Sharp after externalizing the packages in convex.json and adding the "use-node" directive at the top of their file Discord support thread: Image resizing.
-
Another community member tried using Jimp but found it "exceptionally slow" Discord support thread: Image resizing.
The general workflow would be:
- Receive the image in an action
- Process/optimize it using a library like Sharp
- Store the optimized version using
ctx.storage.store() - Save the storage ID to your database
It's worth noting that Convex team members have acknowledged that image transformations would be a valuable addition to the platform, with one mentioning "we have something underway. hoping to get an early version out soon" Discord support thread: Are image transformations supported?.