How to upload only jpeg & gif & png images into public/image

Hello iam new to rubyonrails. Please any one help me out in “How to
upload
only jpeg & gif & png images into public/images using rubyonrails”

Thanks in Advance

Already I go thru this link, I implemented in my application. The images
are
uploaded but those are not as the original images. Overlapped with some
colours. But one image is uploaded successfully its size is 977Bytes.
If it is 2, or 1.4 KB or more than this not uploaded as original images

so plz help me out in this thing

hi there,
I hate when people send me an URL instead of an answer but I think you
should read this one: :slight_smile:
http://wiki.rubyonrails.com/rails/pages/HowtoUploadFiles
to check the file type the example talks about
person[‘picture’].content_type
I’ve never tried it BTW,
HTH!
Enrico

2006/5/4, Surekha M. [email protected]:


“The only thing necessary for the triumph of evil
is for good men to do nothing”
Edmund Burke

Surekha M. wrote:

Already I go thru this link, I implemented in my application. The images
are
uploaded but those are not as the original images. Overlapped with some
colours. But one image is uploaded successfully its size is 977Bytes.
If it is 2, or 1.4 KB or more than this not uploaded as original images

so plz help me out in this thing

Make sure that in your database table you have the data column set to
‘longblob’ not just blob. it will crop the image if you don’t!

jon

Well,

 It looks like no one intends to help you, which is pretty much the 

experience that Ive had on this mailing list. So heres some of my code.
This is in my pcomic_admin controller that allows editors for my
magazine to submit comics. The code is not finished yet. It doesnt
check for errors in alot of places that it should. It also does not
check the file size. Im also wary of allowing uploads to the public
directory. Im thinking that the image should actually go into a sub
folder with black hole permissions, similar to an ftp setup. Maybe
others on this list can give an opinion, that would be nice for once.

Dorian

def create
if @session[‘user’].nil?
redirect_to :action => ‘login’
elsif params[:comicpic].content_type.chomp == “image/jpeg”
@user = User.find(@session[‘user’].id)
File.open("…/public/comics/#{@user.id}/#{params[:comicpic].original_filename}",
“w”) do
|f| f.write(params[:comicpic].read)
end
@comic = Pendingcomic.new(params[:comic])
@comic[‘image_url’] =
“/comics/#{@user.id}/#{params[:comicpic].original_filename}”
@user.pendingcomics.push(@comic)
redirect_to :action => ‘list’
else
redirect_to :action => ‘list’
end
end

Surekha M. wrote:

Hello iam new to rubyonrails. Please any one help me out in “How to
upload
only jpeg & gif & png images into public/images using rubyonrails”

Thanks in Advance

You could also use file_column plugin:
http://www.kanthak.net/opensource/file_column/

You can install the latest revision like this:
script/plugin install
http://opensvn.csie.org/rails_file_column/plugins/file_column/trunk

Then if you want you can generate docs for this plugin:
rake doc:plugins

Now if you want to allow uploading of specific formats you can do:

class Entry < ActiveRecord::Base
file_column :image
validates_file_format_of :field, :in => [“gif”, “png”, “jpg”]
end

And that’s all. Really simple.