Woohoo, IndiePants will finally store uploaded images in the database by default, thanks to the newly improved support for PostgreSQL in ActiveRecord. I did have to switch to the current HEAD of Rails 4.2.1 (which isn’t officially released yet), but other than that, implementing this was trivial. Check out my custom Dragonfly data store which uses a very simple ActiveRecord model to access a just as simple table. This table has a
bytea column, which ActiveRecord now supports as
I could probably have executed queries directly without going through ActiveRecord, but my gut tells me that this will eventually be useful for querying the binaries table. Also, I’m lazy.
Storing binary data in the database often evokes an unpleasant reaction in developers, the biggest worry being about performance. Well, turns out PostgreSQL is actually really good at handling binary data – and even if it wasn’t, it would probably still perform better than pulling files off S3 over and over again. In the end, no matter what you do, you will want to cache served images on the HTTP level (which is heaps of fun with the way Dragonfly works, as you don’t need to manually expire cache keys.) Either way, if you want to host Pants on your own server and don’t want to put binary data into your database, you can simply reconfigure Dragonfly to use S3, the local file system (not recommended), or whatever other data store you prefer.