We have a RoR 3.2 site on Heroku using their production tier PostgreSQL database.
Our site users occasionally upload images of 0.5 - 2MB in size. For different reasons we want to store those images in the database, rather than as files on S3 or similar.
If our site was image heavy, i.e. a Facebook clone, surely storing images in the db would not be a good thing.
Anyway, it is not, so here are some of the reasons for wanting to store a users images in the database:
What is the easiest way to store images in the Heroku PostgreSQL database? Example code or link to a walk-through would be most welcome.
Thanks :)
No problem. Simple File Upload is the easiest way to allow users to add files to your app. We handle all of the tooling surrounding file uploading for you. No cloud storage account needed.
Heroku Postgres delivers the world's most advanced open source database as a trusted, secure, and scalable service that is optimized for developers.
I encourage you to not use your database to store images of that size.
S3 can be backed up very effectively, and is extremely hardened. From a data loss perspective, it's effectively safer then a development postgres database plan with Heroku.
The cost aspect is also not really best practice in this example. Although you're right they only enforce a row limit, I think it would be frowned upon to store large images (0.5 - 2mb) in the development database plan.
Finally, the speed of a transfer to S3 from EC2 (where Heroku is hosted) is very fast due to Amazon's internal networking.
Knowing that, I'd urge you to rethink your desire to store images of that size in a database. See this question for a more in depth analysis on the pros and cons.
There's also a dev center article about using S3 and Heroku.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With