#Is it possible to optimize images as they are uploaded?

3 messages · Page 1 of 1 (latest)

frank yacht
#

Is it possible to optimize images as they are uploaded? in order to save space

tropic impBOT
#

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:

  1. 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.

  2. 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?.

Until native support is available, implementing your own optimization using Node.js libraries in actions is the way to go.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: