Forum: Ruby on Rails How to upload only jpeg & gif & png images into public/image

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1586cffb7dc11f0c02b084b03ccf8fcf?d=identicon&s=25 Surekha Matte (Guest)
on 2006-05-04 09:28
(Received via mailing list)
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
6992e8171ed4afa8b4ad4a8cef31fa29?d=identicon&s=25 Enrico Teotti (Guest)
on 2006-05-04 09:40
(Received via mailing list)
hi there,
I hate when people send me an URL instead of an answer but I think you
should read this one: :-)
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 Matte <ieg.surekha.matte@gmail.com>:
>
>


--
"The only thing necessary for the triumph of evil
is for good men to do nothing"
 Edmund Burke
1586cffb7dc11f0c02b084b03ccf8fcf?d=identicon&s=25 Surekha Matte (Guest)
on 2006-05-04 10:04
(Received via mailing list)
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
4108c0021c64d188494cae8dcfc95fd8?d=identicon&s=25 Jon Mr (jon-d)
on 2006-05-10 23:53
Surekha Matte 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
Cc4f5ad6f8a398757f8ce8ab3a18c6b3?d=identicon&s=25 Dorian (Guest)
on 2006-05-12 14:47
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 Matte 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
F639e0cdf2fa098b535d6ec766b2aee1?d=identicon&s=25 Szymon Nowak (g0nzo)
on 2006-05-12 15:15
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/...

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.
This topic is locked and can not be replied to.