I''m writing an application where the user will be uploading many images and user feedback is essential. I''ve been trying to get the upload progress bar plug-in to work, but thus far have not had any success. I''ve downloaded Sean Treadway''s application code from his site http://sean.treadway.info/demo/upload/ and I followed the steps in his Upload Progress Checklist. I''ve tried this on both my Gentoo and WinXP boxes using the Rails 1.0. def upload case @request.method when :post @message = ''File uploaded: '' + params[:document][:file].size.to_s upload_progress.message = "Simulating some file processing stage 1..." session.update # Dump information about uploads @session[:uploads].each {|k,v| logger.debug("Debug: #{k}----->#{v.completed_percent}")} sleep(3) upload_progress.message = "Continuing processing stage 2..." session.update sleep(3) redirect_to :action => ''show'' finish_upload_status "Hello ''#{@message}''" end end My problem is that no matter the file size by the time to debug statement is reached the entire file has always been uploaded. So the progress bar jumps from 1 to 100 with no in between steps. I can step through with a debugger and see this session being updated with file size, bit rate, etc. information as the file is being uploaded, but no luck with the bar. Should I resign myself to putting up a pretty swirly animated graphic and telling the user "it won''t be long now" ? has anybody had any success with the getting the upload progress bar to work? can anybody provide any sample application code or suggest alternatives to using the progress bar? thanks for any help... -- Posted via http://www.ruby-forum.com/.
It seems you might be missing the upload_status. This is what I''ve done: *** Controller *** class UploadController < ApplicationController upload_status_for :upload_file, :status => :upload_status def upload_file if request.post? # write the file to disk write_file(params[:document][:file]) # redirect to the next page redirect_to :home_url # update the client finish_upload_status "''#{@message}''" end end def upload_status # you can work with the various upload_progress components here... render :inline => ''<%= "#{upload_progress.completed_percent} % complete" %>'', :layout => false end protected def write_file(file) f_name = sanitize_filename(file.original_filename) File.open("#{RAILS_ROOT}/public/images/#{f_name}", "wb") do |f| f.write(file.read) end # closes the file write end def sanitize_filename(file_name) # get only the filename, not the whole path (from IE) just_filename = File.basename(file_name) # replace all none alphanumeric, underscore or perioids with underscore just_filename.sub(/[^\w\.\-]/,''_'') end end *** View *** <div id=''upload_form''> <%= form_tag_with_upload_progress :action => ''upload_file'' %> <%= file_field "document", "file" %> <%= submit_tag "Upload" %> <%= upload_status_text_tag %> <%= end_form_tag %> </div> *** HTH. - josh On Jan 6, 2006, at 8:17 AM, rails-request@lists.rubyonrails.org wrote:> Date: Fri, 06 Jan 2006 16:53:52 +0100 > From: Daniel Holmlund <holmlundlists@gmail.com> > Subject: [Rails] Upload Progress Bar Problems > > I''m writing an application where the user will be uploading many > images > and user feedback is essential. > > I''ve been trying to get the upload progress bar plug-in to work, but > thus far have not had any success. > > I''ve downloaded Sean Treadway''s application code from his site > http://sean.treadway.info/demo/upload/ and I followed the steps in > his > Upload Progress Checklist. > > I''ve tried this on both my Gentoo and WinXP boxes using the Rails 1.0. > > > def upload > case @request.method > when :post > @message = ''File uploaded: '' + > params[:document][:file].size.to_s > > upload_progress.message = "Simulating some file processing > stage 1..." > session.update > > # Dump information about uploads > @session[:uploads].each {|k,v| logger.debug("Debug: > #{k}----->#{v.completed_percent}")} > > sleep(3) > > upload_progress.message = "Continuing processing stage 2..." > session.update > sleep(3) > > redirect_to :action => ''show'' > > finish_upload_status "Hello ''#{@message}''" > end > end > > My problem is that no matter the file size by the time to debug > statement is reached the entire file has always been uploaded. So the > progress bar jumps from 1 to 100 with no in between steps. I can step > through with a debugger and see this session being updated with file > size, bit rate, etc. information as the file is being uploaded, but no > luck with the bar. > > Should I resign myself to putting up a pretty swirly animated graphic > and telling the user "it won''t be long now" ? has anybody had any > success with the getting the upload progress bar to work? can anybody > provide any sample application code or suggest alternatives to > using the > progress bar? thanks for any help...-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060106/34e86873/attachment-0001.html
I also might depend on the weberserver you are using, I remember with older versions of lighttpd getting the same of what you described (but I don''t know about newer lightpd versions) On 1/6/06, Joshua Paul <joshpaul@mac.com> wrote:> > It seems you might be missing the upload_status. This is what I''ve done: > > *** > Controller > *** > class UploadController < ApplicationController > upload_status_for :upload_file, :status => :upload_status > > def upload_file > if request.post? > # write the file to disk > write_file(params[:document][:file]) > # redirect to the next page > redirect_to :home_url > # update the client > finish_upload_status "''#{@message}''" > end > end > > def upload_status > # you can work with the various upload_progress components here... > render :inline => ''<%= "#{upload_progress.completed_percent} % > complete" %>'', :layout => false > end > > protected > > def write_file(file) > f_name = sanitize_filename(file.original_filename) > File.open("#{RAILS_ROOT}/public/images/#{f_name}", "wb") do |f| > f.write(file.read) > end # closes the file write > end > > def sanitize_filename(file_name) > # get only the filename, not the whole path (from IE) > just_filename = File.basename(file_name) > # replace all none alphanumeric, underscore or perioids with > underscore > just_filename.sub(/[^\w\.\-]/,''_'') > end > > end > > *** > View > *** > <div id=''upload_form''> > <%= form_tag_with_upload_progress :action => ''upload_file'' %> > <%= file_field "document", "file" %> > <%= submit_tag "Upload" %> > <%= upload_status_text_tag %> > <%= end_form_tag %> > </div> > > *** > HTH. > > - josh > > On Jan 6, 2006, at 8:17 AM, rails-request@lists.rubyonrails.org wrote: > > Date: Fri, 06 Jan 2006 16:53:52 +0100 > > From: Daniel Holmlund <holmlundlists@gmail.com> > > Subject: [Rails] Upload Progress Bar Problems > > > I''m writing an application where the user will be uploading many images > > and user feedback is essential. > > > I''ve been trying to get the upload progress bar plug-in to work, but > > thus far have not had any success. > > > I''ve downloaded Sean Treadway''s application code from his site > > http://sean.treadway.info/demo/upload/ and I followed the steps in his > > Upload Progress Checklist. > > > I''ve tried this on both my Gentoo and WinXP boxes using the Rails 1.0. > > > > def upload > > case @request.method > > when :post > > @message = ''File uploaded: '' + > > params[:document][:file].size.to_s > > > upload_progress.message = "Simulating some file processing > > stage 1..." > > session.update > > > # Dump information about uploads > > @session[:uploads].each {|k,v| logger.debug("Debug: > > #{k}----->#{v.completed_percent}")} > > > sleep(3) > > > upload_progress.message = "Continuing processing stage 2..." > > session.update > > sleep(3) > > > redirect_to :action => ''show'' > > > finish_upload_status "Hello ''#{@message}''" > > end > > end > > > My problem is that no matter the file size by the time to debug > > statement is reached the entire file has always been uploaded. So the > > progress bar jumps from 1 to 100 with no in between steps. I can step > > through with a debugger and see this session being updated with file > > size, bit rate, etc. information as the file is being uploaded, but no > > luck with the bar. > > > Should I resign myself to putting up a pretty swirly animated graphic > > and telling the user "it won''t be long now" ? has anybody had any > > success with the getting the upload progress bar to work? can anybody > > provide any sample application code or suggest alternatives to using the > > progress bar? thanks for any help... > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- Roberto Saccon - http://rsaccon.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060106/8eb6c4c6/attachment-0001.html
Hi, I too have Rails 1.0 running under apache. But I am getting error message for form_tag_with_upload_progress, it seems it''s not identifying this tag. The same happens in Rails 1.1. It would be very kind of you if you can tell me something in this regard. cheers.. Prasad Daniel Holmlund wrote:> I''m writing an application where the user will be uploading many images > and user feedback is essential. > > I''ve been trying to get the upload progress bar plug-in to work, but > thus far have not had any success. > > I''ve downloaded Sean Treadway''s application code from his site > http://sean.treadway.info/demo/upload/ and I followed the steps in his > Upload Progress Checklist. > > I''ve tried this on both my Gentoo and WinXP boxes using the Rails 1.0. > > > def upload > case @request.method > when :post > @message = ''File uploaded: '' + > params[:document][:file].size.to_s > > upload_progress.message = "Simulating some file processing > stage 1..." > session.update > > # Dump information about uploads > @session[:uploads].each {|k,v| logger.debug("Debug: > #{k}----->#{v.completed_percent}")} > > sleep(3) > > upload_progress.message = "Continuing processing stage 2..." > session.update > sleep(3) > > redirect_to :action => ''show'' > > finish_upload_status "Hello ''#{@message}''" > end > end > > My problem is that no matter the file size by the time to debug > statement is reached the entire file has always been uploaded. So the > progress bar jumps from 1 to 100 with no in between steps. I can step > through with a debugger and see this session being updated with file > size, bit rate, etc. information as the file is being uploaded, but no > luck with the bar. > > > Should I resign myself to putting up a pretty swirly animated graphic > and telling the user "it won''t be long now" ? has anybody had any > success with the getting the upload progress bar to work? can anybody > provide any sample application code or suggest alternatives to using the > progress bar? thanks for any help...-- Posted via http://www.ruby-forum.com/.
Daniel, I tried to get this working for a couple of days on Rails 1.0 and ended up at the exact same place. What I think that I observed was that the Ajax calls to do the updating would not start until the file upload was complete, then the intermediate status polling would begin. So it would go from 0% to 100% and then I would see the Ajax periodical updater calls happen. Unfortunately, I finally gave up. I did not get to debugging within the upload code - I did my debugging on the client side, but my results are consistent with yours. Because this was my very first experience with Ajax and Prototype I thought it best to get some other Ajax stuff working first before I came back to it. If you want to try and work through it together, perhaps we could do that. FWIW, you''re not alone ;). Thanks, Wes (Aside, As I said this was on Rails 1.0 - looks like all of these components moved or disappeared for 1.1 - if you have any insight into where they are in the 1.1 distribution, please advise...) Daniel Holmlund wrote:> I''m writing an application where the user will be uploading many images > and user feedback is essential. > > I''ve been trying to get the upload progress bar plug-in to work, but > thus far have not had any success. > > I''ve downloaded Sean Treadway''s application code from his site > http://sean.treadway.info/demo/upload/ and I followed the steps in his > Upload Progress Checklist. > > I''ve tried this on both my Gentoo and WinXP boxes using the Rails 1.0. > > > def upload > case @request.method > when :post > @message = ''File uploaded: '' + > params[:document][:file].size.to_s > > upload_progress.message = "Simulating some file processing > stage 1..." > session.update > > # Dump information about uploads > @session[:uploads].each {|k,v| logger.debug("Debug: > #{k}----->#{v.completed_percent}")} > > sleep(3) > > upload_progress.message = "Continuing processing stage 2..." > session.update > sleep(3) > > redirect_to :action => ''show'' > > finish_upload_status "Hello ''#{@message}''" > end > end > > My problem is that no matter the file size by the time to debug > statement is reached the entire file has always been uploaded. So the > progress bar jumps from 1 to 100 with no in between steps. I can step > through with a debugger and see this session being updated with file > size, bit rate, etc. information as the file is being uploaded, but no > luck with the bar. > > > Should I resign myself to putting up a pretty swirly animated graphic > and telling the user "it won''t be long now" ? has anybody had any > success with the getting the upload progress bar to work? can anybody > provide any sample application code or suggest alternatives to using the > progress bar? thanks for any help...-- Posted via http://www.ruby-forum.com/.