# Image can not be displayed from database

**URL:** <https://www.ruby-forum.com/t/image-can-not-be-displayed-from-database/129406>\
**Category:** Rails\
**Created:** [February 18, 2008, 10:26am UTC](https://www.ruby-forum.com/t/image-can-not-be-displayed-from-database/129406 "2008-02-18T10:26:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![malioboro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eb8c5e/32.png) [@malioboro](https://www.ruby-forum.com/u/malioboro)\
**Post date:** [February 18, 2008, 10:26am UTC](https://www.ruby-forum.com/t/image-can-not-be-displayed-from-database/129406/1 "2008-02-18T10:26:24Z")

</div>

Hello,

I have problem in displaying image from database, please help me how to  
display my image.

## DATABASE DETAIL

(I not create file name field to save original file name to database)

employee\_name, type data → varchar

…

face\_pict - type data → bolb  
pict\_content - type data → varchar

* * *

## display\_image\_controller.rb

class DisplayImageController \< ApplicationController

def employee\_face  
@employees = Employee.find(params[:id])  
send\_data(@employees.face\_pict, :type =\> @employees.pict\_content,  
:disposition =\> “inline”)  
end

end

* * *

## employee.rhtml

…

\<%= image\_tag(“/display\_image/employee\_face?id=”+employee.id.to\_s, :alt  
=\> employee.name, :class =\> “fix\_pict”) %\>

…

* * *

## THE PROBLEM

I tried the script above for displaying image, when I run it in  
development server, the image is displayed properly. But when I deploy  
it and run it in production server, the image can not be displayed  
without error message.

## My Analysis:

1. I check use Firefox and Opera, the image’s size of file is read  
correctly.
2. My saved picture content is image/jpeg. I check production.log i got  
this :

…  
Processing DisplayImageController#employee (for xx.91.x.210 at  
2008-02-18 03:05:02) [GET]  
Session ID: beec19ee523ea0e8d3838da9800bb48d  
Parameters: {“action”=\>“employee\_face”, “id”=\>“6.png”,  
“controller”=\>“display\_image”}  
Sending data  
Completed in 0.00153 (652 reqs/sec) | Rendering: 0.00003 (2%) | DB:  
0.00043 (27%) | 200 OK  
[[http://mydomain.com/display\_image/employee\_face?id=6.png](http://mydomain.com/display_image/employee_face?id=6.png)]  
…

1. I run this link :  
[http://mydomain.com/display\_image/employee\_face?id=6](http://mydomain.com/display_image/employee_face?id=6) (without .png) and  
my image still can not be displayed. Then i go to production.log again  
and see this new written :

…  
Processing DisplayImageController#employee (for xx.91.x.210 at  
2008-02-18 03:07:12) [GET]  
Session ID: c040263c1e0bb218297918330c82ba14  
Parameters: {“action”=\>“employee\_face”, “id”=\>“6”,  
“controller”=\>“display\_image”}  
Sending data  
Completed in 0.00180 (555 reqs/sec) | Rendering: 0.00003 (1%) | DB:  
0.00063 (34%) | 200 OK  
[[http://mydomain.com/display\_image/employee\_face?id=6](http://mydomain.com/display_image/employee_face?id=6)]  
…

1. I tried another script in my view

* * *

## modified → employee.rhtml

…

…

And after i deployed it using capistrano, the same thing is happened  
again (picture still can not be displayed). Please help me what should  
i do to display my image from database. Thank you very much.

Riand
