How to resize images on Spaces

May 30, 2019 379 views
DigitalOcean

Hi,

I just want to use Spaces like that;

blabla.digitalocean.com/1024x1024/images/image.jpg
blabla.digitalocean.com/600x0/images/image.jpg

and it will give me cropped image as values.

How can it be possible?
We can make it on AWS, but couldnt find any configuration field on Spaces.

2 Answers

I’m also seeking for a similar solution but i’m afraid that is not possible with DigitalOcean Spaces :(

Hi, if Spaces supported redirect bucket lifecycle rule you could redirect the request on a missing resource like

blabla.digitalocean.com/1024x1024/image.jpg to myapp.com/1024x1024/image.jpg

which could be a serverless application that would resize, serve and store missing image transformations on the fly. Ideally, this app should also check for allowed image transformations (e.g 1980x1020, 1024x768) to avoid some security issues.

Another solution would be to configure bucket with a custom subdomain like assets.myapp.com and put it behind Cloudflare. Cloudflare offers service called Workers which can execute some logic per each request. You can also resize images with workers.

If somebody has solved this issue elegantly please share;)

Have another answer? Share your knowledge.