Simple and Easy Image Upload

Hi all,

I’ve done a good 8+ hours of searching for a good solution to my problem
but have had little success finding a nice and easy image upload
solution. Oh, and I am new to rails.

My problem/requirement is that I want to upload an image to the file
system (not the database) as quickly and efficiently as possible. I
currently do not want any resizing or ajax functionality (so no
fleximage/swfupload), just a plain <%= f.file_field :image %> to allow
me access to select the image and upload it to the /public/images/users
folder.

There must be a very easy way to do this in rails. I have noticed that
there are a lot of people uploading directly into the database. Is this
a better way? It seems to me that the database should be strictly for
data.

Thanks in advance and I apologize for the novice questions!

Best regards,
Tony

Hello

I do this on the filesystem with:

(params[:photo] is posted)

file_name = “something”

File.open("#{RAILS_ROOT}/public/writable/submissions/" <<

@user.path << “/tmp/” << file_name, “w”){ |f|
f.write(params[:photo].read)}

and for resize…

image = 

Magick::Image.read("#{RAILS_ROOT}/public/writable/submissions/"
<< @user.path << “/tmp/” << file_name).first

 if !image.nil?

   @type = image.format
   @geometry  = image.columns.to_s + "x" + image.rows.to_s
   @imgcol  = image.image_type

   long_side = (image.columns > image.rows) ? image.columns : 

image.rows

   im = image.change_geometry!(tn) { |cols, rows, img|
   img.resize!(cols, rows) }
   im.write("#{RAILS_ROOT}/public/writable/submissions/" <<

@user.path << “/thumb/” << file_name)
end

On Sun, May 25, 2008 at 6:20 PM, Tony T.

Did you check out paperclip,
Paperclip Tips and Updates,
or attachment_fu, http://clarkware.com/cgi/blosxom/2007/02/24.

You don’t need to use the resizing features and both allow saving to
the file system.

You also don’t want to upload directly to the database. Use the db
just to store meta-data about the image.

best.
mike

On May 25, 12:20 pm, Tony T. [email protected]