I''ve gone through every Rails File-Upload tutorial, but never saw a mention of showing the client the upload progress. ("Progress 25% ......... 37% ............ 49% ........ etc") Has anyone seen anything like this for Ruby? We have an app that needs them to upload huge files and I think this would help. Not just going to a page saying "please wait" - but actually something showing the progress.
On Tue, 22 Mar 2005 14:14:19 -0800, Miles Keaton <mileskeaton-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ve gone through every Rails File-Upload tutorial, but never saw a > mention of showing the client the upload progress. > > ("Progress 25% ......... 37% ............ 49% ........ etc") > > Has anyone seen anything like this for Ruby? > > We have an app that needs them to upload huge files and I think this > would help. Not just going to a page saying "please wait" - but > actually something showing the progress.To do that you need to be able to stat the in-progress upload. The problem is that the client doesn''t know the progress, and the server is normally blocking on the upload. If you can find the in-progress file somehow then you can tell it, but I''m not too familiar with how RoR lets you know that sort of detail. -- Phillip Hutchings http://www.sitharus.com/ sitharus-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org / sitharus-QrR4M9swfipWk0Htik3J/w@public.gmane.org
AFAIK the only way to do this is with lower-level access to the cgi. Otherwise you can fake it by setting up a page posting to an iframe and implementing a javascript animated pseudo-progress bar (or something like the osx rolling beachball thing) that just sits there ''moving'' until its complete. On Tue, 22 Mar 2005 14:14:19 -0800, Miles Keaton <mileskeaton-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ve gone through every Rails File-Upload tutorial, but never saw a > mention of showing the client the upload progress. > > ("Progress 25% ......... 37% ............ 49% ........ etc") > > Has anyone seen anything like this for Ruby? > > We have an app that needs them to upload huge files and I think this > would help. Not just going to a page saying "please wait" - but > actually something showing the progress. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Miles Keaton <mileskeaton-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:> I''ve gone through every Rails File-Upload tutorial, but never saw a > mention of showing the client the upload progress. > > ("Progress 25% ......... 37% ............ 49% ........ etc") > > Has anyone seen anything like this for Ruby? > > We have an app that needs them to upload huge files and I think this > would help. Not just going to a page saying "please wait" - but > actually something showing the progress.The only way I have ever seen this done (which is not often) was with a Java Applet. Patrice -- the Holy Scriptures, which are able to make you wise for salvation through faith in Christ Jesus. (2 Timothy 3:15)
> The only way I have ever seen this done (which is not often) was with > a Java Applet.I''ve seen it done with ASP, but there''s a combination of things going on there. I think it needed some sort of ISAPI module, but I''m not really that knowlageable with IIS/ASP. Anyway, you need a few things: You need to open another window on the client that calls a server-side script. Javascript can do that easily. You need to be able to intercept the HTTP request _at the request level_ - ie when the server is processing it, parse out the content-length header, and make the number of bytes recieved available to an external script. It''s possible. Write an apache/lighthttpd/whatever module that intercepts incoming requests, and Apache request filter might work, and records the stream in something like /tmp/uploads/some_hash_of_known_values and another script that reads that and updates progress. It''s not a job for the casual programmer... -- Phillip Hutchings http://www.sitharus.com/ sitharus-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org / sitharus-QrR4M9swfipWk0Htik3J/w@public.gmane.org
Have a look at Mega Upload at http://www.raditha.com/megaupload/ There are versions for PHP, Perl and JSP. If someone can turn this into a module for Rails, that would be sweet. It has to hook in at the ActionController:CgiRequest level to work... *i think* No need for httpd modules... -- Thomas Fuchs http://www.fesch.at>> The only way I have ever seen this done (which is not often) was with >> a Java Applet. > > I''ve seen it done with ASP, but there''s a combination of things going > on there. I think it needed some sort of ISAPI module, but I''m not > really that knowlageable with IIS/ASP. > > Anyway, you need a few things: > You need to open another window on the client that calls a server-side > script. Javascript can do that easily. > You need to be able to intercept the HTTP request _at the request > level_ - ie when the server is processing it, parse out the > content-length header, and make the number of bytes recieved available > to an external script. > > It''s possible. Write an apache/lighthttpd/whatever module that > intercepts incoming requests, and Apache request filter might work, > and records the stream in something like > /tmp/uploads/some_hash_of_known_values and another script that reads > that and updates progress. > > It''s not a job for the casual programmer... >
On Wed, 23 Mar 2005 00:07:40 +0100, Thomas Fuchs <thomas-9D208sng4xU@public.gmane.org> wrote:> Have a look at Mega Upload at http://www.raditha.com/megaupload/ > > There are versions for PHP, Perl and JSP. If someone can turn this into > a module > for Rails, that would be sweet. > > It has to hook in at the ActionController:CgiRequest level to work... > *i think* > > No need for httpd modules...Heh. MegaUpload runs a perl CGI to spit out the data received to a file and records progress in another file, and a complementary script reads the progress file and does the progress bar. It then reads the file in to PHP and uses parse_str to bring the variables in to the environment. It should be possible to do in rails - spit the upload to a temp file, and then invoke the CGI to read from the file rather than STDIN... -- Phillip Hutchings http://www.sitharus.com/ sitharus-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org / sitharus-QrR4M9swfipWk0Htik3J/w@public.gmane.org
As a starting point, create a file in <rails app root>/lib/intercept_post with these contents, and include it in yor application.rb with require_dependency ''intercept-post'' ----8< cut here -- intercept_post.rb -- class CGI module QueryExtension alias old_read_query_params read_query_params def read_query_params case env_table[''REQUEST_METHOD''] when ''POST'' stdinput.binmode if stdinput.respond_to?(:binmode) STDERR << "Trying to read in raw POST DATA with CONTENT_LENGTH" << env_table[''CONTENT_LENGTH''] content = stdinput.read(Integer(env_table[''CONTENT_LENGTH''])) || '''' env_table[''RAW_POST_DATA''] = content.freeze else old_read_query_params end end end end ----8< cut here -- intercept_post.rb -- This will magically print the message into the server log file... So, you''d just have to read the data from stdinput in in chunks (like in the megaupload perl-script ''upload.cgi'') Maybe I''ll do a lib for this, if i''ve enough time... Thomas Am 23.03.2005 um 0:22 schrieb Phillip Hutchings:> On Wed, 23 Mar 2005 00:07:40 +0100, Thomas Fuchs <thomas-9D208sng4xU@public.gmane.org> > wrote: >> Have a look at Mega Upload at http://www.raditha.com/megaupload/ >> >> There are versions for PHP, Perl and JSP. If someone can turn this >> into >> a module >> for Rails, that would be sweet. >> >> It has to hook in at the ActionController:CgiRequest level to work... >> *i think* >> >> No need for httpd modules... > > Heh. MegaUpload runs a perl CGI to spit out the data received to a > file and records progress in another file, and a complementary script > reads the progress file and does the progress bar. It then reads the > file in to PHP and uses parse_str to bring the variables in to the > environment. > > It should be possible to do in rails - spit the upload to a temp file, > and then invoke the CGI to read from the file rather than STDIN... > -- > Phillip Hutchings > http://www.sitharus.com/ > sitharus-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org / sitharus-QrR4M9swfipWk0Htik3J/w@public.gmane.org > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
It can be done, I''ve done it in java using just servlets but its not very nice, you''d have to open a popup window and poll (using refresh every couple of seconds) the currently uploaded file size against the file size I brought this up once on the irc channel and was told that rubys cgi cant handle this as its written becuase the request only goes through once its complete or something along those lines, would be great if rails would do this though Patrice Neff wrote:>Miles Keaton <mileskeaton-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes: > > > >>I''ve gone through every Rails File-Upload tutorial, but never saw a >>mention of showing the client the upload progress. >> >>("Progress 25% ......... 37% ............ 49% ........ etc") >> >>Has anyone seen anything like this for Ruby? >> >>We have an app that needs them to upload huge files and I think this >>would help. Not just going to a page saying "please wait" - but >>actually something showing the progress. >> >> > >The only way I have ever seen this done (which is not often) was with >a Java Applet. > >Patrice > > >
Actually, my first try doesn''t work, but this does: Copy the method ''def read_multipart(boundary, content_length)'' from cgi.rb (in your ruby installation dir) to a file <rrailsappdir>lib/intercept_multipart.rb, make sure it''s surrounded by: class CGI module QueryExtension << here goes copy >> end end Include in application.rb If you put in a $stderr.print "Remaining data = #{content_length} bytes\n" just after c = if bufsize < content_length stdinput.read(bufsize) else stdinput.read(content_length) end You will see webrick printing "Remaining data = " lines. This output could just be saved to a temporary file or a session var (?), so a special action could (maybe with ajax helpers) could query periodically. Thomas Am 23.03.2005 um 0:35 schrieb Thomas Fuchs:> As a starting point, create a file in <rails app > root>/lib/intercept_post with these contents, > and include it in yor application.rb with require_dependency > ''intercept-post'' > > ----8< cut here -- intercept_post.rb -- > > class CGI > module QueryExtension > > alias old_read_query_params read_query_params > > def read_query_params > case env_table[''REQUEST_METHOD''] > when ''POST'' > stdinput.binmode if stdinput.respond_to?(:binmode) > STDERR << "Trying to read in raw POST DATA with > CONTENT_LENGTH" << env_table[''CONTENT_LENGTH''] > content = > stdinput.read(Integer(env_table[''CONTENT_LENGTH''])) || '''' > env_table[''RAW_POST_DATA''] = content.freeze > else > old_read_query_params > end > end > end > end > > ----8< cut here -- intercept_post.rb -- > > This will magically print the message into the server log file... So, > you''d just have to read the > data from stdinput in in chunks (like in the megaupload perl-script > ''upload.cgi'') > > Maybe I''ll do a lib for this, if i''ve enough time... > > Thomas > > Am 23.03.2005 um 0:22 schrieb Phillip Hutchings: > >> On Wed, 23 Mar 2005 00:07:40 +0100, Thomas Fuchs <thomas-9D208sng4xU@public.gmane.org> >> wrote: >>> Have a look at Mega Upload at http://www.raditha.com/megaupload/ >>> >>> There are versions for PHP, Perl and JSP. If someone can turn this >>> into >>> a module >>> for Rails, that would be sweet. >>> >>> It has to hook in at the ActionController:CgiRequest level to work... >>> *i think* >>> >>> No need for httpd modules... >> >> Heh. MegaUpload runs a perl CGI to spit out the data received to a >> file and records progress in another file, and a complementary script >> reads the progress file and does the progress bar. It then reads the >> file in to PHP and uses parse_str to bring the variables in to the >> environment. >> >> It should be possible to do in rails - spit the upload to a temp file, >> and then invoke the CGI to read from the file rather than STDIN... >> -- >> Phillip Hutchings >> http://www.sitharus.com/ >> sitharus-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org / sitharus-QrR4M9swfipWk0Htik3J/w@public.gmane.org >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
I''ve put up a first version of a library for this here: http://www.fesch.at/ror/upload_progress/ Feedback welcome. -- Thomas Am 22.03.2005 um 23:14 schrieb Miles Keaton:> I''ve gone through every Rails File-Upload tutorial, but never saw a > mention of showing the client the upload progress. > > ("Progress 25% ......... 37% ............ 49% ........ etc") > > Has anyone seen anything like this for Ruby? > > We have an app that needs them to upload huge files and I think this > would help. Not just going to a page saying "please wait" - but > actually something showing the progress. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >