# Simple and Easy Image Upload

**URL:** <https://www.ruby-forum.com/t/simple-and-easy-image-upload/138603>\
**Category:** Rails\
**Created:** [May 25, 2008, 6:20pm UTC](https://www.ruby-forum.com/t/simple-and-easy-image-upload/138603 "2008-05-25T18:20:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bagadoughnuts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@bagadoughnuts](https://www.ruby-forum.com/u/bagadoughnuts)\
**Post date:** [May 25, 2008, 6:20pm UTC](https://www.ruby-forum.com/t/simple-and-easy-image-upload/138603/1 "2008-05-25T18:20:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bagadoughnuts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@bagadoughnuts](https://www.ruby-forum.com/u/bagadoughnuts)\
**Post date:** [May 25, 2008, 7:09pm UTC](https://www.ruby-forum.com/t/simple-and-easy-image-upload/138603/2 "2008-05-25T19:09:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bagadoughnuts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@bagadoughnuts](https://www.ruby-forum.com/u/bagadoughnuts)\
**Post date:** [May 25, 2008, 7:10pm UTC](https://www.ruby-forum.com/t/simple-and-easy-image-upload/138603/3 "2008-05-25T19:10:30Z")

</div>

Did you check out paperclip,  
[Paperclip Tips and Updates](http://giantrobots.thoughtbot.com/2008/5/15/paperclip-tips-and-updates),  
or attachment\_fu, [http://clarkware.com/cgi/blosxom/2007/02/24](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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
