Actually i have came across a situation where i will have to store an image in the database and show the same image.. for this purpose i have used LONGBLOB field in mysql and stored the image.. I have to show this image to the user from db.. and i dont knwo how to show the image in this way.. I have got answer for this in php on http://www.weberdev.com/get_example-4062.html(php code.) There is some function called Header in php but i dont know about rails... Pls help me out.. Thanks and regards Saurabh Purnaye firstname.lastname@example.org
, from the top of my head - you can make a script which retrieves image data (and use this script in src attribute for your tag) The controller of the mentioned script should set "Content-Type" header, for instance, like this:
response.headers["Content-Type"] = "image/gif"
After that you just need to output image field content to stdout.
The type of course depends on image formats you store.
I've had to deal with a similar problem...but since pulling large data from the database may not be very efficient (extra db load, pulling data over the network not to mention that your app server (i.e. Mongrel) now has to serve them where previously nginx/apache could have), I found a good strategy is to cache images from the database to the standard location in the filesystem (in public/images) and let your webserver serve them in the traditional manner.
What I do is cache all images on application startup and then cache them again if they are modified. In order to do this I created an fs_dump! method on the class that encapsulates image assets: