Loading...

mason-users@lists.sourceforge.net

[Prev] Thread [Next]  |  [Prev] Date [Next]

Re: [Mason] Mason File Upload Progress Bar MK Wed Nov 10 15:00:14 2010

On Wed, 10 Nov 2010 14:39:45 +0000
Scott Dolan <[EMAIL PROTECTED]> wrote:
> I am currently using a CGI method you describe and it does work.
[...]
>> From: Christofer Abrahamsson [mailto:[EMAIL PROTECTED]
> Use the cgi:ajax fetch source from perlmonks.
> perl code example: http://pastebin.com/mKDML4hx

Here's a couple of suggestions:

1) You can do this via CGI (a la the pastebin example) from within a
mason app if you create an independent CGI script, and call it as such
from the html page using ajax (ie, don't involve mason in the progress
bar).  

2) Even simpler: roll your own javascript AJAX code and have it poll an 
.mhtml page (via js setInterval) that does exactly what that pastebin
example does: check the current size of the file on the server and
calculate the % done.  So, eg, rather than this line from the pastebin:

<script language="Javascript">
setInterval("check_status(['check_upload__1', 'rand_string',
                'uploadedfile'], ['statusbar']);",
        '1000'
)
</script> 

Which depends upon CGI::ajax, use something like this in the page
source (this uses jQuery, but AJAX is AJAX...):

<script language="Javascript">
setInterval(
        "$.ajax({
                url: progress_bar.mhtml,
                data: "{file:name_of_uploading_file}{totalsize:size of
file}", 
                success: function(html) { /* progress bar code */ }
        });",
        '1000'
)
</script> 

So "progress_bar.mhtml" is just mason perl that checks the current file
size, calculates the percentage done, and returns some html for the
progress bar (the javascript success function implements this).

Nb, my jQuery syntax may be a bit off, but the general idea I am
100% positive will work.  What's *most important here* is that you
understand ajax methodology.  If not, cut n' paste coding will only get
you so far (so if you want that progress bar, start learning...).  

There is simply *no way* to do this without using ajax  -- or flash, or
applets, which probably you could find an existing thing of that
sort which will work independent of Mason, but sort of overkill.   Point
being, this IS NOT simply a server side affair, and mason is a server
side technology.

-- 
"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
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mason-users