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


Posts Tagged ‘ruby’

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

Sunday, May 27th, 2007

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?

Ruby "gem cleanup" returns "Unknown command cleanup"

Friday, May 18th, 2007
root@redhut:/usr/lib/ruby/gems/1.8# gem cleanup
ERROR:  While executing gem ... (RuntimeError)
Β    Unknown command cleanup

It's a bug in 0.9.3, and it will be fixed in an upcoming release.