Reputation: 6589
I've found some similar questions, and good link on the topic. Such as this one (Easiest way to store images in database on Heroku?), where the top answer is to re-think using their DB and instead go with S3.
What I need is store 120 100KB images. That's it. There is no dynamic aspect. It's not like I have 10,000 users, and each one needs to store their profile picture. None of that. I just need to store 120 100KB images. The amount of images will never never change, neither growing or shrinking. 3 years from now, the same 120 images will be all that there is.
For these reasons, I want to store these in my DB. S3 is overkill, could cost some, extra time and cost needed implementing that solution, etc. In my DB, it's a measly 12MB which is a fraction of a fraction of the DB's total size.
How can I store the images? What datatype should I use and how can I upload them into my DB?
Upvotes: 1
Views: 2194
Reputation: 324295
Just store them as bytea
fields in a table. Insert them using a script in whatever your preferred language is and its database adapter. e.g. using Python with psycopg2
you'd open('filename','rb')
the file, then pass it as a query parameter to the execute
method when doing your INSERT
.
For images that small there's no point using pg_largeobject
and the lo
wrapper, which can be useful for really big files. The only real advantage of that is that you can use lo_import
to read the files directly into the database.
Upvotes: 1