Ratnavel Sundaramurthi wrote:> Hi,
>
> I was trying to integrate a scanner with my application. After a long
> struggle i succeeded in integrating, Now i could see the captured image
> in my browser, But now i need to upload that image in buffer to the file
> system(Server Side) or to data base.
>
> How to carry out this any suggestions?
>
> Thanks,
> Ratnavel.
-------------------------
Store Image in Database
-------------------------
~> ruby script/generate model picture
----------------
Migration
----------------
class CreatePicture < ActiveRecord::Migration
def self.up
create_table :global_configs do |t|
t.column :data, :blob
t.column :content, :string
end
end
def self.down
drop_table :kamars
end
end
~> rake db:migrate
------------------------------
VIEW # for FORM to Upload
------------------------------
<% form_tag ({:action => "upload_pict" }, {:multipart =>
true}) do
%>
<%= file_field "web", "image" %><br><%=
submit_tag "Upload" %>
<% end %>
<%= end_form_tag %>
--------------------------------------------
CONTROLLER # store image into DB
--------------------------------------------
class TeaPociController < ApplicationController
...
def upload_pict
if params[:web][''image''].size > 1
@type_file =
File.extname(params[:web][''image''].original_filename.gsub(/[^\w._-]/,""))
#Check Image, Image should be Picture
if @type_file == ".jpeg" || @tipe_file == ".gif" ||
@tipe_file == ".bmp"
|| @tipe_file == ".jpg" || @tipe_file == ".png"
@picture = Picture.new
@picture.data = params[:web][''image''].read
@picture.content = params[:web][''image''].content_type.chomp
if @picture.save
flash[:notice] = "Image is stored in database successfully."
end
else
flash[:notice] = "File is not an image."
end
else
flash[:notice2] = "Image is empty."
end
end
...
end
----------------------
CONTROLLER
----------------------
class TeaPociController < ApplicationController
...
def display_image
@real_picture = Picture.find(params[:id])
send_data(@real_picture.data,
:type => @real_picture.content,
:disposition => "inline")
end
end
-------------------------------
VIEW #DISPLAY IMAGE IN RHTML
-------------------------------
<image src="/tea_poci/display_image?id=<%= @any.id %>">
GoodLuck,
Reinhart
http://teapoci.blogspot.com
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---