# Image from database

**URL:** <https://www.ruby-forum.com/t/image-from-database/127853>\
**Category:** Rails\
**Created:** [February 1, 2008, 9:16pm UTC](https://www.ruby-forum.com/t/image-from-database/127853 "2008-02-01T21:16:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ankit2584](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/51bf81/32.png) [@ankit2584](https://www.ruby-forum.com/u/ankit2584)\
**Post date:** [February 1, 2008, 9:16pm UTC](https://www.ruby-forum.com/t/image-from-database/127853/1 "2008-02-01T21:16:03Z")

</div>

Hello,  
I want to displa a thumbnail image from the database. this is like when  
a person logs in his thumbnail will be shown. The photo will be stored  
in the database(MSSQL 2000) as binary data.Please help me to upload a  
thumbnail sized image and display it on the screen.  
Thank you.

---

<div class="post-metadata">

**Author:** ![ankit2584](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/51bf81/32.png) [@ankit2584](https://www.ruby-forum.com/u/ankit2584)\
**Post date:** [February 2, 2008, 12:15am UTC](https://www.ruby-forum.com/t/image-from-database/127853/2 "2008-02-02T00:15:10Z")

</div>

On 2/1/08, Ank Ag [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I want to displa a thumbnail image from the database. this is like when  
> a person logs in his thumbnail will be shown. The photo will be stored  
> in the database(MSSQL 2000) as binary data.Please help me to upload a  
> thumbnail sized image and display it on the screen.

Where’s the code representing your own failed attempt?

Storing images in the database is a bad idea in the realm of  
performance. Why not use the database you already have, the file  
system?

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![ankit2584](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/51bf81/32.png) [@ankit2584](https://www.ruby-forum.com/u/ankit2584)\
**Post date:** [February 2, 2008, 2:13am UTC](https://www.ruby-forum.com/t/image-from-database/127853/3 "2008-02-02T02:13:08Z")

</div>

Greg D. wrote:

> On 2/1/08, Ank Ag [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I want to displa a thumbnail image from the database. this is like when  
> > a person logs in his thumbnail will be shown. The photo will be stored  
> > in the database(MSSQL 2000) as binary data.Please help me to upload a  
> > thumbnail sized image and display it on the screen.
> 
> Where’s the code represe

Here the piece of code:

def photo  
@person = Person.find(params[:id])  
send\_data(@person.uploaded\_data,  
:filename=\>@person.filename,  
:type =\> @person.content\_type,  
:disposition =\> ‘inline’)

end

but when i goto [http://localhost:3000/person/photo/2308](http://localhost:3000/person/photo/2308)  
I get the following error.

private method `gsub’ called for #Array:0x47454c4

I also after reading a forum did the following  
modified the following methods in the sqlserver\_adapter.rb as follows  
and things seems to work fine for me.

def self.string\_to\_binary(value)  
Base64.encode64(value)  
end

def self.binary\_to\_string(value)  
Base64.decode64(value)  
end

undefined method `unpack’ for #Array:0x4611800
