Storing photos in database

Forums > Book - Chapter 7 > Storing photos in database

Login to post a new topic

Author Message
lars
Member since 10 Aug 19:35
0 posts

I am interesting in storing the photos in a database instead of the file system to enable only logged in users to see the images.
I gave it a try yesterday, and ran into a few challenges after changing the migrations to include the extra table (and column) necessary.
The problem occur in the photo partial. The helper public_filename for photo probably does not make sense anymore, as the link should point to the database instead of the filesystem. Any suggestions how to get around this?

alan
Member since 26 Jun 23:06
0 posts

You’re right, the filename no longer makes any sense – basically, you’ll have to create a method that retrieves the blob from the database and then sends that to the browser. I’ve got some code around that does just that – I’ll see if I can find it.

lars
Member since 10 Aug 19:35
0 posts

Thanks Alan, I would appreciate som help on this. Lars