Trying to upload image in database

Hi All,

I got the Error message when i try to upload a image file into database
using Ruby on Rails ,

PGError: ERROR: unterminated quoted string at or near “'����”
LINE 1: …O photos (“description”, “picture”) VALUES(‘flower’, '����
^
: INSERT INTO photos (“description”, “picture”) VALUES(‘flower’,
'�����JFIF��������C�
aaa






#%$“”!&+7/&)4)!"0A149;>>>%.DIC<H7=>;���C’)

I am using
DataBase :Postgresql 8.2 version
OS : windowsXp
Rails : version 1.2.4 and server : mongrel

If anybody could know the solution for above problem, let me know as
soon as possible.

Thanks in advance.

I would recommend storing them in base64 format.

require ‘base64’

ascii = Base64::encode64(binary)

binary = Base64::decode64(ascii)

You could do this in a filter of course. I just made a dummy
attribute called “image_binary” which, upon setting, base64 encodes
the data, and when reading base64 decodes it.

–Michael

Michael G. wrote:

I would recommend storing them in base64 format.

require ‘base64’

ascii = Base64::encode64(binary)

binary = Base64::decode64(ascii)

You could do this in a filter of course. I just made a dummy
attribute called “image_binary” which, upon setting, base64 encodes
the data, and when reading base64 decodes it.

–Michael

This is my RHTML code to upload image path from user:

Picture

<%= file_field ‘photo’, ‘photo’ %>

Ruby code to save in Database (postgresql):

def create
@photo = Photo.new(params[:photo])
if @photo.save
redirect_to :action => ‘list’
else
render :action => ‘new’
end
end

Now i would like to know where i should add your code

(mentioned above)

Thanks
Priya