Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageOptimization in Rails 5 ActiveStorage

I'm planning to upgrade Rails to 5.2 in one of my websites and introduce ActiveStorage, as of right now I use Paperclip with paperclip_optimizer. One of the negative sides is that I will lose the optimizer, when replacing paperclip with ActiveStorage. How can I implement automatically image optimization on user uploads in ActiveStorage?

like image 330
kallelundgren93 Avatar asked Mar 19 '18 10:03

kallelundgren93


2 Answers

It's possible by creating a custom Variation. There is a good example here:

https://prograils.com/posts/rails-5-2-active-storage-new-approach-to-file-uploads

like image 143
Mike Buckbee Avatar answered Sep 28 '22 18:09

Mike Buckbee


If you are on AWS you can create Lambda function that can listen to an S3 bucket for uploads, and runs image optimization on the newly uploaded files.

like image 45
Alex Ganov Avatar answered Sep 28 '22 20:09

Alex Ganov