# Multiple file upload form

**URL:** <https://www.ruby-forum.com/t/multiple-file-upload-form/49945>\
**Category:** Rails\
**Created:** [December 10, 2005, 6:00pm UTC](https://www.ruby-forum.com/t/multiple-file-upload-form/49945 "2005-12-10T18:00:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![scottnj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b9e5f3/32.png) [@scottnj](https://www.ruby-forum.com/u/scottnj)\
**Post date:** [December 10, 2005, 6:00pm UTC](https://www.ruby-forum.com/t/multiple-file-upload-form/49945/1 "2005-12-10T18:00:30Z")

</div>

I am trying to modify the image upload example in the Agile book to  
handle mtltiple files.

I have been playing with it for a while now, but no luck.

Do I have to create a loop, and do each file seperate, or can I just  
save an array of files?

How can I set up my form and controller to handle this? Will I have to  
modify the model?

---

<div class="post-metadata">

**Author:** ![scottnj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b9e5f3/32.png) [@scottnj](https://www.ruby-forum.com/u/scottnj)\
**Post date:** [December 10, 2005, 10:05pm UTC](https://www.ruby-forum.com/t/multiple-file-upload-form/49945/2 "2005-12-10T22:05:03Z")

</div>

Hi,

Scott I have stuggled with the same problem. Ultimately I have resorted  
to file\_column, a plugin that can handle multiple files. You can find it  
at [http://www.kanthak.net/opensource/file\_column/](http://www.kanthak.net/opensource/file_column/) .

To handle multiple files, you should put something like the following in  
your model:

class Entry \< ActiveRecord::Base  
file\_column :image1  
file\_column :image2  
file\_column :image3  
end

Kind regards,

Nick

scottnj wrote:

> I am trying to modify the image upload example in the Agile book to  
> handle mtltiple files.
> 
> I have been playing with it for a while now, but no luck.
> 
> Do I have to create a loop, and do each file seperate, or can I just  
> save an array of files?
> 
> How can I set up my form and controller to handle this? Will I have to  
> modify the model?

---

<div class="post-metadata">

**Author:** ![scottnj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b9e5f3/32.png) [@scottnj](https://www.ruby-forum.com/u/scottnj)\
**Post date:** [December 10, 2005, 11:24pm UTC](https://www.ruby-forum.com/t/multiple-file-upload-form/49945/3 "2005-12-10T23:24:19Z")

</div>

Nick S. \<nick.snels@…\> writes:

> class Entry \< ActiveRecord::Base
> 
> > I am trying to modify the image upload example in the Agile book to  
> > handle mtltiple files.
> > 
> > I have been playing with it for a while now, but no luck.
> > 
> > Do I have to create a loop, and do each file seperate, or can I just  
> > save an array of files?
> > 
> > How can I set up my form and controller to handle this? Will I have to  
> > modify the model?

I used the following js to create a dynamic array of files and then loop  
through  
the array. (stickman’s multiple upload javascript)  
[http://snipurl.com/ko7u](http://snipurl.com/ko7u)

then use something like:

@files = []  
params[:file].each {|k,v| @files[k.to\_i] = v if v.size\>0}

for file in @files  
do stuff  
end

Works a treat. Note- I found that for some reason an empty file element  
seemed  
to be created which screwed everything up so added v.size\>0.

Hope this is of interest.

Graham.

---

<div class="post-metadata">

**Author:** ![scottnj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b9e5f3/32.png) [@scottnj](https://www.ruby-forum.com/u/scottnj)\
**Post date:** [December 10, 2005, 11:34pm UTC](https://www.ruby-forum.com/t/multiple-file-upload-form/49945/4 "2005-12-10T23:34:26Z")

</div>

g.arrowsmith wrote:

> I used the following js to create a dynamic array of files and then loop  
> through  
> the array. (stickman’s multiple upload javascript)  
> [http://snipurl.com/ko7u](http://snipurl.com/ko7u)

I saw this and am considering it, but I need something to work if  
javascript is disabled.
