mongreleers, This is a hack for adding basic upload progress support to Mongrel. Currently, you can monitor the upload of any POST. I''m sure some work needs to be done to get it functioning with Rails. Save as lib/mongrel/progress. Anyway, here''s how to start Mongrel with it: require ''mongrel'' require ''mongrel/camping'' require ''mongrel/progress'' config = Mongrel::Configurator.new :host => host do listener :port => port do uri "/", :handler => Mongrel::Camping::CampingHandler.new(ParkPlace) uri "/progress", :handler => Mongrel::ProgressHandler.new uri "/favicon", :handler => Mongrel::Error404Handler.new("") trap("INT") { stop } run end end config.join Yeah, so, notice the ProgressHandler class and the require. In your forms: <form action="?upload_id=XXX" enctype="multipart/form-data">...</form> Since the handler is mounted at ''/progress'', you can hit ''/progress?upload_id=XXX'' to read the stats: size: 55575 received: 11131 Left to do: * XML/YAML/JSON output. (based on the Accept header.) * Support for X-Upload-ID, X-Progress-ID, progress_id. (?) _why -------------- next part -------------- A non-text attachment was scrubbed... Name: progress.rb Type: application/x-ruby Size: 2683 bytes Desc: not available Url : http://rubyforge.org/pipermail/mongrel-users/attachments/20060511/d4ca5b4c/attachment.bin
On Thu, 2006-05-11 at 11:56 -0600, why the lucky stiff wrote:> mongreleers, > > This is a hack for adding basic upload progress support to Mongrel. > Currently, you can monitor the upload of any POST. I''m sure some work > needs to be done to get it functioning with Rails.Sweet, why. I''m actually working on something like this for the documentation as a plugin example. I''ll chat with you about stealing this and doing the distribution. How do you think it''d work with Rails? I''ll help you turn it into a plugin too. That''ll be a good start for the doc. -- Zed A. Shaw http://www.zedshaw.com/ http://mongrel.rubyforge.org/
I did some hacking on this in a Rails app and got basic ajax calls returning the status in JSON. The main change to Mongrel was the addition of Rails'' MIME parsing classes. The progress status then looks like: respond_to do |accepts| accepts.html { out.write("size: #{status[''size'']}\nreceived: #{status[''received'']}\n") } accepts.js do head[''Content-Type''] = ''text/javascript'' out.write("{size:#{status[''size'']},received:#{status[''received'']}}") end end if status Here''s the simple rails view / javascript I used to conduct the test: <% @upid = Time.now.to_i %> <%= start_form_tag "?upload_id=#{@upid}", :multipart => true, :onsubmit => "monitorUploadProgress(#{@upid})" %> <p><%= file_field_tag :upload %></p> <p><%= submit_tag :Upload %></p> </form> <div id="results"></div> function monitorUploadProgress(upid) { new PeriodicalExecuter(function() { new Ajax.Request(''/progress?upload_id='' + upid, { asynchronous:true, evalScripts:true, method:''get'', onComplete:function(request) { new Insertion.Bottom(''results'', "<pre><code>" + request.responseText + "</code></pre>"); } }); }, 3); } -- Rick Olson http://techno-weenie.net -------------- next part -------------- A non-text attachment was scrubbed... Name: mongrel_responds_to.diff Type: application/octet-stream Size: 10455 bytes Desc: not available Url : http://rubyforge.org/pipermail/mongrel-users/attachments/20060511/8ba26353/attachment.obj
Rick Olson wrote:> respond_to do |accepts| > accepts.html { out.write("size: #{status[''size'']}\nreceived: > #{status[''received'']}\n") } > accepts.js do > head[''Content-Type''] = ''text/javascript'' > out.write("{size:#{status[''size'']},received:#{status[''received'']}}") > end > end if statusLet''s get it checked in. What about: respond_to do |accepts| accepts.html { out.write("size: #{status[''size'']}\nreceived: #{status[''received'']}\n") } accepts.js { out.write("{size:#{status[''size'']},received:#{status[''received'']}}") } end if status We''re storing all the mimetypes, let''s do a nice thing. _why
On Thu, 2006-05-11 at 17:37 -0500, Rick Olson wrote:> I did some hacking on this in a Rails app and got basic ajax calls > returning the status in JSON. The main change to Mongrel was the > addition of Rails'' MIME parsing classes. The progress status then > looks like: >Whoa, that''s an assload of Rails code suddenly showing up in Mongrel. Let''s not check this in yet because there''s already a simple MIME system in Mongrel. Also, I don''t want this in the Mongrel code base, but rather as a GemPlugin distributed separately. I''ll get with you and Why on how we can do that. -- Zed A. Shaw http://www.zedshaw.com/ http://mongrel.rubyforge.org/
On Thu, 2006-05-11 at 17:06 -0600, why the lucky stiff wrote:> Rick Olson wrote: > > respond_to do |accepts| > > accepts.html { out.write("size: #{status[''size'']}\nreceived: > > #{status[''received'']}\n") } > > accepts.js do > > head[''Content-Type''] = ''text/javascript'' > > out.write("{size:#{status[''size'']},received:#{status[''received'']}}") > > end > > end if status > Let''s get it checked in. What about: > > respond_to do |accepts| > accepts.html { out.write("size: #{status[''size'']}\nreceived: > #{status[''received'']}\n") } > accepts.js { > out.write("{size:#{status[''size'']},received:#{status[''received'']}}") } > end if status > > We''re storing all the mimetypes, let''s do a nice thing.Hold up, don''t check anything in. I want to do this as a GemPlugin people can add. I''m also dead against including tons of Rails code. Typically this ends up going really bad for the other frameworks as demonstrated when Camping was doing AR and causing issues with Rails AR. Let''s coordinate this before shooting it into the main Mongrel core. -- Zed A. Shaw http://www.zedshaw.com/ http://mongrel.rubyforge.org/
Zed Shaw
2006-May-12 01:31 UTC
[Mongrel] New projects/mongrel_upload_progress (Was: Upload progress "plugin")
Hey Why and Rick, I carved you a little corner of the svn just for your snazzy upload progress code. You now can do all your own stuffs in the projects/mongrel_upload_progress directory. It''s all setup and ready to be turned into a gemplugin. Basic process is read: http://mongrel.rubyforge.org/docs/gem_plugin.html So you get an idea of how they''re crafted, then here''s the RDoc: http://mongrel.rubyforge.org/gem_plugin_rdoc/ Once you got a handle on that, you just fill in the lib with your code, hook up the init.rb and you''re golden. Let me know if there''s *minor* core API changes that need to be made to get this stuff working. To test it out you just build the gem with the Rakefile, then run your test app. The theory is if you did it right folks should be able to install your handlers by writing a config/mongrel.conf and using the -S command line option (or whatever Why does for Camping). Ping me up as you do this so I can help you through the stuff. I''ll be interested in writing a document on how it was made. On Thu, 2006-05-11 at 17:06 -0600, why the lucky stiff wrote:> Rick Olson wrote: > > respond_to do |accepts| > > accepts.html { out.write("size: #{status[''size'']}\nreceived: > > #{status[''received'']}\n") } > > accepts.js do > > head[''Content-Type''] = ''text/javascript'' > > out.write("{size:#{status[''size'']},received:#{status[''received'']}}") > > end > > end if status > Let''s get it checked in. What about: > > respond_to do |accepts| > accepts.html { out.write("size: #{status[''size'']}\nreceived: > #{status[''received'']}\n") } > accepts.js { > out.write("{size:#{status[''size'']},received:#{status[''received'']}}") } > end if status > > We''re storing all the mimetypes, let''s do a nice thing.-- Zed A. Shaw http://www.zedshaw.com/ http://mongrel.rubyforge.org/
Zed Shaw wrote:> On Thu, 2006-05-11 at 17:06 -0600, why the lucky stiff wrote: > >> Let''s get it checked in. > Hold up, don''t check anything in.I''m sorry, very bad choice of words. I am tremendously sorry about that. As a branch or a plugin, exactly. We talked about this in the presence of indian_chief earlier. I will consult his log. _why
Apparently Analagous Threads
- upload progress bar don''t work...please help
- Definitive guide for upload progress
- Mongrel upload progress not showing progress on production server
- mongrel_upload_progress question/possible suggestion
- No return status from mongrel upload progress (and thus no updates on the bar)