Multiple file upload w/Rails 2.x


#1

Been searching forever. I need to create a multiple file uploader. I
can do single files, but I want to do multiple. I think flash is my
only option. But my problem is I can’t get flash to communicate. May
be something with the auth code, I’ve tried passing the auth code to
Flash and back to Rails in POST but no luck.

Anyone know a good resource? I want to be able to understand what’s
going on, and preferably build it myself (I’ve built it with AS3/PHP
before).


#2

we are using swfupload, which works pretty well. It allows you to show
progress of each upload etc. We switched to this because the customer
wanted a multi-select file dialog.

before that, we had rolled our own js solution, which allowed the user
to pick one file at a time, but upload them all at once. basically, a
normal file upload, with a ‘add another file’ link which dynamically
built another file upload element in the dom. was pretty easy to set up
actually.

Cheers
Simon


#3

That looks like a start. But what about integrating it with Rails?
That’s my problem, I can’t get Flash to talk to rails. I don’t see any
documentation for it on their site.


#4

It does a normal post, just like any other js that is generated from
rails, so it’s just a matter of reading the params on the other end.


#5

There is no Rails solution for this, cause upload is normally controlled
by
the server… If you (like me) don’t want or can’t use Flash based
solutions,
you should work using modules on the server and creating client side
solutions using Javascript.

At this moment i’m working in something like that, the solution is
really
not trivial, but not very complicated.

Here you can see an example (about progress bar):

http://railsillustrated.com/screencast-file-uploads-progress-in-rails-passenger.html

One side effect for this approach is that this turn much more
complicated to
test the process, but between choose a dependency at client side and a
dependency at server/development side, i really prefer the second one.

On Thu, May 14, 2009 at 8:43 PM, removed_email_address@domain.invalid
removed_email_address@domain.invalidwrote:

That looks like a start. But what about integrating it with Rails?
That’s my problem, I can’t get Flash to talk to rails. I don’t see any
documentation for it on their site.


Everton J. Carpes
Mobile: +55 53 9129.4593
MSN: removed_email_address@domain.invalid
UIN: 343716195
Jabber: removed_email_address@domain.invalid

“If art interprets our dreams, the computer executes them in the guise
of
programs!” - Alan J. Perlis


#6

I can’t understand if you are telling that for me, but i will reply
anyway… if your reply was for the Flash solution, sorry (just ignore).

It does a normal post, just like any other js that is generated from
rails,

so it’s just a matter of reading the params on the other end.

Yes, is just that, except by the fact that “the other end” should be
working
in a very specific environment… to test this kind of thing, you should
be
using in development environment the same environment of production
(with
the same server and module plus traffic band limiter to simulate the
thing)
and at test environment a lot of complex mocks to simulate the same
environment… this is not so trivial like it would be.


Everton J. Carpes
Mobile: +55 53 9129.4593
MSN: removed_email_address@domain.invalid
UIN: 343716195
Jabber: removed_email_address@domain.invalid

“If art interprets our dreams, the computer executes them in the guise
of
programs!” - Alan J. Perlis


#7

I actually have my own uploader class for Flash, which uploads
multiple files one after the other. The only thing I need to know is
how to get Rails to retrieve that file. Any simple solutions/tutorials?


#8

params[:file_upload_field] will just be a slightly enhanced File
object; call it’s original_filename method to get the path it was
uploaded to on the server and you can use your everyday FileUtils,
File, and IO methods on it to do as you please.


#9

sorry, local_path will return the tempfile’s path on the server;
original_filename will return… the basename of the original file
(even accomodating for IE’s wonkiness)


#10

I can mess with it again… but if I use Flash, is there anything out
of the ordinary I need to do (eg with the authentication in Rails
2.x)? I used the same Flash script that worked to send to PHP to Ruby
and I couldn’t get Ruby to do anything with the files (using Rails
script that worked with static html uploads).


#11

As to the CSRF part, you’ll need to pass the authenticity_token into
Flash somehow (my Flash is pretty terrible, so I wouldn’t really know
how to do that; i guess a start would be knowing #
{form_authenticity_token} is the String containing the authtoken).
Otherwise you can call

skip_before_filter :verity_authenticity_token, :only =>
‘upload_action’

To skip the authenticity token check, if you feel your app has strong
enough security without it.