# MS-SQL deliveres binary image as array

**URL:** <https://www.ruby-forum.com/t/ms-sql-deliveres-binary-image-as-array/152384>\
**Category:** Rails\
**Created:** [November 3, 2008, 12:17pm UTC](https://www.ruby-forum.com/t/ms-sql-deliveres-binary-image-as-array/152384 "2008-11-03T12:17:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lackyg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d07c76/32.png) [@lackyg](https://www.ruby-forum.com/u/lackyg)\
**Post date:** [November 3, 2008, 12:17pm UTC](https://www.ruby-forum.com/t/ms-sql-deliveres-binary-image-as-array/152384/1 "2008-11-03T12:17:14Z")

</div>

Hello!

I need to display images stored in a MS-SQL database but I get the  
following error:

NoMethodError (undefined method `unpack' for #<Array:0x48cbff0>): c:/ruby/lib/ruby/1.8/base64.rb:59:in`decode64’

I guess its because MS-SQL delivers an arry…

Is there a solution to this problem??

Please help me!  
lacky

---

<div class="post-metadata">

**Author:** ![lackyg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d07c76/32.png) [@lackyg](https://www.ruby-forum.com/u/lackyg)\
**Post date:** [November 3, 2008, 4:05pm UTC](https://www.ruby-forum.com/t/ms-sql-deliveres-binary-image-as-array/152384/2 "2008-11-03T16:05:02Z")

</div>

> NoMethodError (undefined method `unpack' for #<Array:0x48cbff0>): c:/ruby/lib/ruby/1.8/base64.rb:59:in`decode64’

From this is looks to me like some code is attempting to decode the  
image data from Base64. Are you sure your image data is encoded using  
Base64? I tend to doubt it. MS-SQL is likely just storing the raw binary  
data. So it makes sense the you would have an array of bytes.

It would be helpful if you could post the code that you’re using to  
display the image. Normally in RoR there is a method that returns the  
raw image data from a request with the proper content-type header. For  
example the content-type header for a JPEG would be image/jpeg.

Somehow your application needs to tell the browser what the binary data  
represents. It could be pretty much anything (JPEG, GIF, PDF, etc). This  
is typically accomplished using the send\_data method.

Here’s an example:  
def sales\_graph  
png\_data = Sales.plot\_for(Date.today.month)  
send\_data(png\_data, :type =\> “image/png”, :disposition =\> “inline”)  
end

GÃ¼nther Lackner wrote:

> Hello!
> 
> I need to display images stored in a MS-SQL database but I get the  
> following error:
> 
> NoMethodError (undefined method `unpack' for #<Array:0x48cbff0>): c:/ruby/lib/ruby/1.8/base64.rb:59:in`decode64’
> 
> I guess its because MS-SQL delivers an arry…
> 
> Is there a solution to this problem??
> 
> Please help me!  
> lacky

---

<div class="post-metadata">

**Author:** ![lackyg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d07c76/32.png) [@lackyg](https://www.ruby-forum.com/u/lackyg)\
**Post date:** [November 4, 2008, 8:17am UTC](https://www.ruby-forum.com/t/ms-sql-deliveres-binary-image-as-array/152384/3 "2008-11-04T08:17:31Z")

</div>

Hello!

Thanks for your reply. The function in the controller looks like this:

def get\_front\_image  
device = Device.find(:first, :conditions =\> [“ID1 = ?”, params[:id]])  
@front = device.THUMBFRONT  
send\_data (@front,:type =\> ‘image/gif’,  
:filename =\> ‘front\_view.gif’,  
:disposition =\> ‘inline’)  
end

You might be right, it could be a byte array… but how can I display  
it??

best regards  
lacky

Robert W. wrote:

> > NoMethodError (undefined method `unpack' for #<Array:0x48cbff0>): c:/ruby/lib/ruby/1.8/base64.rb:59:in`decode64’
> 
> From this is looks to me like some code is attempting to decode the  
> image data from Base64. Are you sure your image data is encoded using  
> Base64? I tend to doubt it. MS-SQL is likely just storing the raw binary  
> data. So it makes sense the you would have an array of bytes.
> 
> It would be helpful if you could post the code that you’re using to  
> display the image. Normally in RoR there is a method that returns the  
> raw image data from a request with the proper content-type header. For  
> example the content-type header for a JPEG would be image/jpeg.
> 
> Somehow your application needs to tell the browser what the binary data  
> represents. It could be pretty much anything (JPEG, GIF, PDF, etc). This  
> is typically accomplished using the send\_data method.
> 
> Here’s an example:  
> def sales\_graph  
> png\_data = Sales.plot\_for(Date.today.month)  
> send\_data(png\_data, :type =\> “image/png”, :disposition =\> “inline”)  
> end
> 
> GÃ¼nther Lackner wrote:
> 
> > Hello!
> > 
> > I need to display images stored in a MS-SQL database but I get the  
> > following error:
> > 
> > NoMethodError (undefined method `unpack' for #<Array:0x48cbff0>): c:/ruby/lib/ruby/1.8/base64.rb:59:in`decode64’
> > 
> > I guess its because MS-SQL delivers an arry…
> > 
> > Is there a solution to this problem??
> > 
> > Please help me!  
> > lacky

---

<div class="post-metadata">

**Author:** ![lackyg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d07c76/32.png) [@lackyg](https://www.ruby-forum.com/u/lackyg)\
**Post date:** [November 5, 2008, 10:06am UTC](https://www.ruby-forum.com/t/ms-sql-deliveres-binary-image-as-array/152384/4 "2008-11-05T10:06:38Z")

</div>

Hi all!

I FOUND A SOLUTION!!!

Just follow this article:

[http://blog.mcmoyer.com/2007/9/18/using-ms-sqlserver-with-rails](http://blog.mcmoyer.com/2007/9/18/using-ms-sqlserver-with-rails)

best regards  
Lacky
