Craig Box's journeys, stories and notes...


Ways to get an upload progress bar in a Ruby on Rails application

Ready?

  • The "Sean Treadway method" Requires fcgid and Apache. Pretty much superseded by...
  • Mongrel's upload progress extension. Your upload form launches an AJAX updater that says "How far thru' the file am I, foo'?" every N seconds. However, because your upstream bandwidth is hosed (especially on 128Kbps DSL), it tends to take N+15 seconds to get a response. Can be notoriously hard to make go. (Hint, try sudo gem cleanup, and not running your code as root, or not being on a VPN to the server. Any combination of these might have helped.)
    • Mongrel tends to be run behind a load balancing proxy. These sometimes buffer requests so you end up sending 100% of the file before the server knows a file is coming. A solution appears to be to run another Mongrel instance on another port to accept uploads. This is a solution that lots of people suggest but no-one actually says "I do this, here's how".
    • Apache users might need to use mod_proxy_html to rewrite your links, if your JS doesn't have URLs generated with Rails' url_to helpers. This may or may not exist for Apache 2.2.
    • I have everything working up to this point, but the progress doesn't actually display for me using Apache 2.2 as my load balancer.
  • There is a Mongrel Upload Progress with Streaming extention, based on XUpload. The author sounds like he's been working on making it use JSON rather than Javascript, but there's not been a release since. May or may not work with Safari.
  • Use lighttpd and it's upload progress engine. I presume you'd just use it to proxy Mongrel. (Not really for me, as I'm somewhat tied to Apache on my SSL port.)
  • Merb, which seems to be Ruby off Rails. Again, it is used as a secondary server that just accepts uploads, but I have no idea how you'd run a merb and hand uploads to your Rails application. Comments to this welcome.
  • Shockwave Macromedia Adobe Flash, which does all the upload progress client-side. There's a nice degrades-to-Javascript engine called SWFUpload to try here.

Confused yet?

Tags: , ,

7 Responses to “Ways to get an upload progress bar in a Ruby on Rails application”

  1. Brad Ediger says:

    I've been using mongrel_upload_progress for 8 months or so now on one of my apps. I run pound -> pack of mongrels (nginx wasn't as popular then).

    Pound doesn't buffer requests, so any of the mongrels can handle the upload and upload progress pings. I use the DRb backend to coordinate between Mongrels.

  2. Craig says:

    I run Apache on the server that I want to run the application on, hosting other sites on the SSL port, so ultimately I need to continue using Apache myself.

    Thanks for your comment though - good to know.

  3. [...] my previous post on upload progress in Rails, I can now [...]

  4. Ryan says:

    Great list, thanks!

    The Sean Treadway method is apparently the only one in this list I can use on my host server (Site5), as they are using FastCGI.

    Major problem there is it extends the deprecated form_tag, which will break in Rails 2.0, I believe. Any suggestions on how to use with form_for?

  5. [...] are a ton of possible upload progress solutions for Web applications that need them. I had been using the upload progress that came with Merb, but [...]

  6. For the last bullet point, check out ActiveUpload.

  7. marius says:

    (however, swfupload has moved to http://www.swfupload.org)

Leave a Reply to Jason’s postings and stuff » Flash Upload Progress for Rails with FancyUpload for mootools