MongrelUploadProgressDb by David Stevenson ds@elctech.com ======================= This plugin extends the mongrel_upload_progress gem to allow upload progress information to be stored in a database table, rather than in memory or using distributed ruby. Every 3 seconds, upload_progress for a given upload_id is stored in the database table. ====================== Usage ====================== After installing the plugin, you should invoke the setup method at the end of environment.rb as follows: Upload.setup The following options are possible to the setup method: :object_name -- model where statuses are stored (default => :upload_status) :id_method_name -- method where upload_id's are stored (default => :upid) :remaining_method_name -- method where remaining byte count is to be stored (default => :remaining) :total_size_method_name -- method where total byte count is to be stored (default => :total) You'll also need a table to store upload statuses. Here's a sample migration: def self.up create_table :upload_statuses do |t| t.column :upid, :string, :null => false t.column :remaining, :integer, :default => 0 t.column :total, :integer, :default => 0 t.column :updated_at, :datetime end add_index(:upload_statuses, :upid, :unique => true) end Like mongrel_upload_progress, you must also pass a parameter in your form called "upload_status", and set its value to something unique. Here's how I accomplished that: <% @upid = Time.now.to_i.to_s + (rand * 10000).to_i.to_s %> <% form_for :stuff, :url => stuff_path(:upload_id => @upid), :html => {:multipart => true, :onsubmit => "UploadProgress.monitor('#{escape_javascript @upid}', '#{progress_stuff_path}')"} do |f| %> Finally, in the controller, you must make a method which reports upload status back to the browser. Here's mine: def progress render :update do |page| @status = UploadStatus.find_by_upid(params[:upload_id]) page.upload_progress.update(@status.total, @status.progress) if @status && @status.total > 0 end end