# Uploading files

**URL:** <https://www.ruby-forum.com/t/uploading-files/81945>\
**Category:** Rails\
**Created:** [January 16, 2007, 1:40pm UTC](https://www.ruby-forum.com/t/uploading-files/81945 "2007-01-16T13:40:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![emuen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/96bed5/32.png) [@emuen](https://www.ruby-forum.com/u/emuen)\
**Post date:** [January 16, 2007, 1:40pm UTC](https://www.ruby-forum.com/t/uploading-files/81945/1 "2007-01-16T13:40:12Z")

</div>

Hi there.

Is there anyone, who can direct me to a site, that explains how to  
upload a file via RoR

Im a beginner

---

<div class="post-metadata">

**Author:** ![emuen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/96bed5/32.png) [@emuen](https://www.ruby-forum.com/u/emuen)\
**Post date:** [January 16, 2007, 2:05pm UTC](https://www.ruby-forum.com/t/uploading-files/81945/2 "2007-01-16T14:05:28Z")

</div>

Emil K. wrote:

> Hi there.
> 
> Is there anyone, who can direct me to a site, that explains how to  
> upload a file via RoR
> 
> Im a beginner

look up file\_column:

[http://www.kanthak.net/opensource/file\_column/](http://www.kanthak.net/opensource/file_column/)

i think there are other things out there (in fact, maybe even better)  
but i think this quite basic and good enough.  
hth,

s

---

<div class="post-metadata">

**Author:** ![emuen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/96bed5/32.png) [@emuen](https://www.ruby-forum.com/u/emuen)\
**Post date:** [January 16, 2007, 2:06pm UTC](https://www.ruby-forum.com/t/uploading-files/81945/3 "2007-01-16T14:06:22Z")

</div>

((ignore the Rmagik stuff in the meantime))

---

<div class="post-metadata">

**Author:** ![emuen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/96bed5/32.png) [@emuen](https://www.ruby-forum.com/u/emuen)\
**Post date:** [January 16, 2007, 2:10pm UTC](https://www.ruby-forum.com/t/uploading-files/81945/4 "2007-01-16T14:10:06Z")

</div>

Other options are:

acts\_as\_attachment:  
[http://technoweenie.stikipad.com/plugins/show/Acts+as+Attachment](http://technoweenie.stikipad.com/plugins/show/Acts+as+Attachment)

or

flex\_image: [http://beautifulpixel.textdriven.com/](http://beautifulpixel.textdriven.com/)

Kind regards,

## Nick S.

> **[Ruby on Rails hosting companies - Compare, review and find your next ROR host](https://railshostinginfo.com)**
>
> Are you looking for a good and reliable Ruby on Rails hosting company? We have lined them up so you can easily compare and review them.

Compare and review Rails hosting

---

<div class="post-metadata">

**Author:** ![emuen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/96bed5/32.png) [@emuen](https://www.ruby-forum.com/u/emuen)\
**Post date:** [January 16, 2007, 2:15pm UTC](https://www.ruby-forum.com/t/uploading-files/81945/5 "2007-01-16T14:15:01Z")

</div>

You can also put this kind of stuff in your controller (for example) or  
for DRY put it in your model…

```
@file = params[:image][:img]
if @file.original_filename.length > 0
  filename = session[:dirname] + "/" + @file.original_filename
  File.open(filename, "w") { |f| f.write(@file.read) }
end
redirect_to :action => "index"

```

Emil K. wrote:

> Hi there.
> 
> Is there anyone, who can direct me to a site, that explains how to  
> upload a file via RoR
> 
> Im a beginner

---

<div class="post-metadata">

**Author:** ![emuen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/96bed5/32.png) [@emuen](https://www.ruby-forum.com/u/emuen)\
**Post date:** [January 16, 2007, 3:58pm UTC](https://www.ruby-forum.com/t/uploading-files/81945/6 "2007-01-16T15:58:33Z")

</div>

Nicolas B. wrote:

> You can also put this kind of stuff in your controller (for example) or  
> for DRY put it in your model…
> 
> ```
> @file = params[:image][:img]
> if @file.original_filename.length > 0
> filename = session[:dirname] + "/" + @file.original_filename
> File.open(filename, "w") { |f| f.write(@file.read) }
> end
> redirect_to :action => "index"
> 
> ```

DRY ?? What is this ?

- Emil

---

<div class="post-metadata">

**Author:** ![emuen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/96bed5/32.png) [@emuen](https://www.ruby-forum.com/u/emuen)\
**Post date:** [January 16, 2007, 4:46pm UTC](https://www.ruby-forum.com/t/uploading-files/81945/7 "2007-01-16T16:46:26Z")

</div>

On 1/16/07, Emil K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > ```
> > redirect_to :action => "index"
> > 
> > ```
> 
> DRY ?? What is this ?

DRY means Don’t Repeat Yourself, a common mantra for rails developers.  
For instance, using one of the above mentioned plugins means this  
will probably be taken care of for you.

If you’re on rails 1.2 and were looking at acts\_as\_attachment, I’d  
suggest my refactored update attachment\_fu. It has an #uploaded\_data  
accessor that handles the above code in your model.

–  
Rick O.  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)
