Hi MK
Can I check I've understood your plan?
As I understand it there are two separate server-side scripts. One is called by
the form POST which handles the file upload - using $r->upload or CGI.pm and
the other is the AJAX handler which is called repeatedly and just queries the
file size. The first would be able to create the destination filepath and would
return this to the browser - in various ways but say by creating a Javascript
snippet that would be the variable used by the AJAX.
//get upload file
open(NEWFILE, "path/to/uploaded/file") ;
print NEWFILE while <$fh>; //where $fh is the filehandle returned by either
CGI.pm or Apache2::Request
close(NEWFILE);
return path/to/uploaded/file to the browser.
Now the AJAX in the browser polls the second server script to get the size of
this file as per your AJAX snippet.
I have a couple of questions:
i. Where do you get the total size from? Surely the server does not know this
until it has finished the upload?
ii. In a server script which is uploading a large file presumably mod_perl
does not wait until it has received the whole file to start outputting onto the
output stream?
Thanks
Justin
> MK,
> Make sense... So, create a page like below. Unfortunately, I tried this
> and it does not work because %init and %perl are only execute after the
> complete file has been transfer to the server. So, call to file size always
> match total size.. This is even true for very large files ...
>
> <%args>
> $filepath
> $totalsize
> </%args>
>
> <%init>
> #attempt to read the file size of filepath unfortunately...
> # This is not execute until the complete file has been upload..
> </%init>
>
> <%perl>
> #attempt to read the file size of filepath unfortunately...
> # This is not execute until the complete file has been upload..
> </%perl>
> -----Original Message-----
> From: MK [mailto:halfcountp...@intergate.com]
> Sent: Wednesday, November 10, 2010 4:20 PM
> To: Scott Dolan
> Cc: Mason-users@lists.sourceforge.net
> Subject: Re: [Mason] Mason File Upload Progress Bar
>
> On Wed, 10 Nov 2010 20:39:31 +0000
> Scott Dolan <sdo...@v12groupinc.com> wrote:
>> Thanks MK,
>> But, I am looking for a pure mason and ajax and/or jquery solution.
>> I am currently have a solution similar to pastebin work using CGI and
>> ajax.
>
> I think you do not understand, sorry if I was not clear. Suggestion #2 is
> pure mason with ajax (which would be the best way to do it).
>
> Nb, jQuery is just a javascript library that (in part) implements "ajax"
> methods (you can also write them yourself, but most people will recommend
> against this because of hassles with maintenance, different browsers, etc).
> "Ajax" itself is just conceptual:
>
> http://en.wikipedia.org/wiki/Ajax_(programming)
>
> It exploits the *client side* potential of javascript, which (short of flash,
> et. al.) is necessary for communicating with the server and modifying page
> content without replacing the entire page.
>
> Anyway, lemme try and explain that second suggestion again:
>
> 1) You write a mason script that accepts two parameters, a filepath and a
> total size. This page checks the current size of the file on the server, and
> turns that into a percentage of the total size. This is used to create the
> html mark-up for the progress bar, which is what that .mhtml file creates (so
> it's not a complete html page, it's just a partial "component").
>
> 2) Your file upload page fires a javascript rountine on submit that uses
> setInterval (a standard javascript function) to poll the server, via some
> AJAX method, every 1000 milliseconds. The ajax call is to the mason page
> from #1. It receives fresh html from the mason component which you use to
> update (replace) the progress bar, so that it reflects the size of the file
> on the server.
>
> So, that's just a mason page and some javascript (probably making use of a
> library such as jQuery). Make sense?
>
> MK
>
> --
> "The angel of history[...]is turned toward the past." (Walter Benjamin)
>
> ------------------------------------------------------------------------------
> The Next 800 Companies to Lead America's Growth: New Video Whitepaper
> David G. Thomson, author of the best-selling book "Blueprint to a
> Billion" shares his insights and actions to help propel your
> business during the next growth cycle. Listen Now!
> http://p.sf.net/sfu/SAP-dev2dev
> _______________________________________________
> Mason-users mailing list
> Mason-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/mason-users
------------------------------------------------------------------------------
Centralized Desktop Delivery: Dell and VMware Reference Architecture
Simplifying enterprise desktop deployment and management using
Dell EqualLogic storage and VMware View: A highly scalable, end-to-end
client virtualization framework. Read more!
http://p.sf.net/sfu/dell-eql-dev2dev
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users