0

I am having an issue retrieving an image that is stored as a blob in a legacy oracle database. When I go to http://server/images/id/type I receive a no implicit conversion of Symbol into Integer error.

I have the following setup:

GemFile

gem 'rails', '3.2.13'
gem 'activerecord-oracle_enhanced-adapter'
gem 'ruby-oci8'

Table

CREATE TABLE "SCHEMA"."IMAGE_TABLE" 
(   "IMG_TYPE_SEQ_NO" NUMBER(12,0), 
"IMG_TYPE" VARCHAR2(10 BYTE), 
"IMG_DESC" VARCHAR2(60 BYTE), 
"IMG_LENGTH" NUMBER, 
"IMG_BLOB" BLOB
);

Model

class Image < ActiveRecord::Base
self.table_name = 'schema.image_table'

def self.image_by_id_and_type(id, type)
  where(
    'img_type_seq_no = :id and img_type = :type',
     id: id, type: type
  )
end

Controller

class ImagesController < ApplicationController

  def show_image
    @image = Image.image_by_id_and_type(params[:id], params[:type])
    send_data @image[:img_blob], type: 'image/gif', disposition: 'inline'
  end

end

I have tried using send_data @image.img_blob and get a undefined method error with it.

What am I doing wrong?

Thanks, Chris

Update:

I wonder if there is an issue of type conversion. The blob image was persisted via a java swing application that converted it to a java byte array. Could this be the issue? If so, how do I convert a java byte array into something send_data can understand?

2 Answers 2

0

This is a wild guess. Please try with

def show_image
    @image = GiftCardImage.image_by_id_and_type(params[:id].to_i, params[:type])
    send_data @image[:img_blob], type: 'image/gif', disposition: 'inline'
end

In your model

class Image < ActiveRecord::Base
self.table_name = 'schema.image_table'

def self.image_by_id_and_type(id, type)
  where("img_type_seq_no = ? and img_type = ?", id, type)
end
1
  • I modified the examples above to remove domain specific names that may have caused confusion. I missed them when I was trying to generify it.<br/><br/>Your suggestion, while cleaner looking, did not work. I am getting the same error message.
    – cwperry
    Jul 17, 2013 at 13:14
0
@image = Image.image_by_id_and_type(params[:id], params[:type])

is returning an ActiveRecord::Relation object, so in order to get the actual value from it, I had to call first.

send_data @image.first[:img_blob], type: 'image/gif', disposition: 'inline'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.