Fleximage News - gem, S3 and Heroku
December 13th, 2009
First of all, yes I am a douchebag for no posting anything in forever. Life has been busy, but I’m starting to recollect my voice, and we will see how it goes.
So, Fleximage! recently a few things have gone into the popular image plugin.
1. Ruby Gem
gem install fleximage
Currently just 1.0.0, but you no longer need to install fleximage as a plugin. It now works as a gem. Just install the gem and add a config.gem 'fleximage' to your app’s initialization and you have finer version control and an all around cleaner way to manage your fleximage installation.
2. Amazon S3
You can now use Amazon S3 as a store for your master images.
1 2 3 4 5 6 7 8 9 10 11 12 |
class Photo < ActiveRecord::Base acts_as_fleximage do s3_bucket 'mywebsite-com-user-uploads' end end # a new initializer require 'aws/s3' AWS::S3::Base.establish_connection!( :access_key_id => 'my_s3_key_here', :secret_access_key => 'my_s3_secret_here' ) |
Now new Photos will be uploaded to and read from your Amazon S3 account. This isn’t super fast, but with proper page caching it shouldn’t be a big problem. And there are some server configurations where file system storage is not possible, and database storage is impractical.
Which brings us to…
3. Heroku
The S3 support now allows fleximage to run on Heroku without database image storage. Use S3 for storing your images, and you are done!
What about cacheing? you ask. Well Heroku uses Cache-Control headers to auto cache your content. And fleximage will automatically render it’s images with a 24 hour cache header. So it should just work. Just note that it’s not simple to expire a cached image. So i usually construct my fleximage models so that the image on a particular model will never change. Meaning that if I want a new image, I probably just want to delete that model and upload a new image to a new one. or you can just wait a day for the new image to reappear.
I’ll be working on better solutions to Heroku caching when I can, but for now this should work well enough for most apps.
Leave a Reply