You are here: Forums Ask a Rails expert how to show an image stored in...
Posted in Forums : Ask a Rails expert
|
Authority 37
Posting Rating 69
Sign in to rate this post
|
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.. |
Authority 62
Posting Rating 97
Sign in to rate this post
|
, from the top of my head – you can make a script which retrieves image data (and use this script in src attribute for your 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. |
|
Authority 37
Posting Rating 69
Sign in to rate this post
|
thanks naveen.. |
Authority 75
Posting Rating 95
Sign in to rate this post
|
I handle this with an images controller: |
Authority 62
Posting Rating 44
Sign in to rate this post
|
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: |
Authority 0
Posting Rating 0
Sign in to rate this post
|
I made something similar but with PDF files. |
Ask a Rails expert : How to use mephisto
Ask a Rails expert : How to use mephisto
Ask a Rails expert : will_paginate customization problem
Ask a Rails expert : BackgroundRB still wants 'development' environment...?
Ask a Rails expert : activescaffold, sql exception
Ask a Rails expert : Passing non-english chars in query string
Ask a Rails expert : Rails and 2D barcodes
Ask a Rails expert : apache giving proxy error
Ask a Rails expert : Custom Responses w/ 'extra' information...?
Ask a Rails expert : Log rotation in rails