# Multiple File Upload

**URL:** <https://www.ruby-forum.com/t/multiple-file-upload/96943>\
**Category:** Rails\
**Created:** [July 3, 2006, 4:51pm UTC](https://www.ruby-forum.com/t/multiple-file-upload/96943 "2006-07-03T16:51:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrrl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/dbc845/32.png) [@mrrl](https://www.ruby-forum.com/u/mrrl)\
**Post date:** [July 3, 2006, 4:51pm UTC](https://www.ruby-forum.com/t/multiple-file-upload/96943/1 "2006-07-03T16:51:44Z")

</div>

Hello together,

I developed a file upload in my application like this (files uploaded  
belong to a project):

## project\_controller.rb:

def upload\_attachment  
project = Project.find(@params[:id])  
begin  
project.attachments.create(params[:attachment])  
rescue  
flash[:attachment\_error] = “Error at Upload”  
end  
redirect\_to :action =\> “edit\_project”, :id =\> project  
end

## attachment\_model:

def attachment=(attachment\_field)  
self.name = base\_part\_of(attachment\_field.original\_filename)  
self.content\_type = attachment\_field.content\_type.chomp  
self.data = attachment\_field.read  
end

def base\_part\_of file\_name  
name = File.basename(file\_name)  
name.gsub(/[^\w.\_-]/, ‘’)  
end

## edit\_project.rhtml:

\<%= form\_tag({:action =\> ‘upload\_attachment’, :id =\> @project},  
:multipart =\> true ) %\>  
  
Title: \<%= text\_field(“attachment”,“title”) %\> \<%=  
file\_field(“attachment”,“attachment”) %\>  
  
\<%= submit\_tag (“Upload”) %\>  
\<%= end\_form\_tag %\>

Now the PROBLEM: What have I to write to get a multiple file upload, for  
example 5 files with one click on the Upload-Button. Is there anyone who  
knows something?

Thank you very much!

My english is not the best, but I hope everything is understandable - if  
not, please ask.

---

<div class="post-metadata">

**Author:** ![mrrl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/dbc845/32.png) [@mrrl](https://www.ruby-forum.com/u/mrrl)\
**Post date:** [December 23, 2007, 1:20pm UTC](https://www.ruby-forum.com/t/multiple-file-upload/96943/2 "2007-12-23T13:20:16Z")

</div>

Hey,

There a a bunch of them all over the internet. You just need to find  
out more about them and decide which one suits your needs.

Here are a few that I can name by mind: Acts As Attachment, File  
Column Plugin and FlexImage, attachment\_fu, upload\_column and many  
others.

Try googling the plugins I gave you…

See ya  
Thiago G.

---

<div class="post-metadata">

**Author:** ![mrrl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/dbc845/32.png) [@mrrl](https://www.ruby-forum.com/u/mrrl)\
**Post date:** [December 24, 2007, 4:22am UTC](https://www.ruby-forum.com/t/multiple-file-upload/96943/3 "2007-12-24T04:22:51Z")

</div>

On 22 Dec 2007, at 19:06, B wrote:

> I want to do a multiple file upload with Ruby. I want to let my users  
> upload pictures on my website to their account. I’m looking for  
> something with a nice interface. I was wondering if you knew of any  
> plugins/gems i can use

Interface is something you have to whip up yourself. Rails isn’t a  
ready-made application, it’s a framework. Although maybe one of the  
open source rails application might fit your need, I’ll let other  
people recommend you apps that could be useful.

On the Rails side, I’d advise you to use attachment\_fu to handle the  
uploaded files. For the uploading interface, you have a choice  
between a wide variety of methods: SWFUpload (http://  
[www.swfupload.org/](http://www.swfupload.org/)) uses Flash to stream multiple files to Rails (+  
upload progress/client side file size and type checking/â€¦),  
reponds\_to\_parent uses the iframe method for handling uploads  
(posting the files form to an iframe to simulate ajax upload) or you  
can just use normal forms to handle your upload.

Best regards

Peter De Berdt
