On Thu, 11 Nov 2010 00:10:12 -0000
"Justin Wyllie" <jus...@justinwylliephotography.com> wrote:
> It looks like Apache/mod_perl does not start to return anything until
> it has received the whole file. 
>I guess because the request is not complete until it has all arrived,
>which is Scott's problem. So your
> AJAX script is in the same page as the upload form. 

No.  It does not matter if the request is not complete yet.  The file
upload and the progress bar request *are separate and unrelated*.

You are not asking apache for the information; you are literally
checking the current file size via perl.  The ajax request to create and
maintain and update the progress bar is separate from the upload
request.  The upload request is the form submission; the progress bar
is created by a separate request that starts at the same time because it
fires via javascript  "onsubmit".   Unless configured very strangely,
Apache handles separate requests in parallel.  Eg, if someone is
uploading something to your site, it does not mean no one can look at
anything until that one upload is complete.  Since the progress bar
requests are separate and have nothing to do with the upload request,
they will be fulfilled right away, just like normal page requests that
Apache will fulfill while it is uploading data for some other request.

> So. You do need to know in advance where you will be storing the file
> right? 

Yep.

> I still don't see where you are getting the total size from in your
> AJAX call?

You would get the filename by checking the form.field.value client side,
which will remain the same throughout the upload, even after the form
has been submitted (you must also use ajax in the form submission tho,
or the page will clear -- or you could return a fresh "uploading"
page, with a hidden form within it containing the file name or some
session id; I think it might have to be the latter). But WRT to the file
size: you're right, I didn't think too hard about that one. There seem
to be a couple of ways to get information about local files via things
like ActiveX, but I doubt they are very dependable. You could just have
a "kb uploaded" instead of a percentage.

The total size of the file should be in the Content-Length of the
actual upload request, but of course you won't be able to use that if
even the <%init%> doesn't fire!

That would seem to be an unfortunate aspect of mason: I have done some
mod_perl programming, it certainly is not an issue there. You can
hook into the request cycle at any point, eg, during the parsing of the
HTTP headers, but before the content is read, meaning you could get the
Content-Length before the upload begins (you can use this to cancel
requests that are too long). In fact, this would be a very simple module
to write and I suppose would work for most mason users.

I'm curious about this myself so maybe when I get a few minutes I will
see what I can come up with and I'll report back here.  Most of the
work is client side.  I believe it should be possible, if file uploads
can be done via ajax(?), to access the HTTP headers created by the
browser in the XMLHttpRequest, which is created by the client before
the request is even sent. So you could then split off a parallel process
(javascript is great for this thanks to setInterval and setTimeout)
that sends the content-length to "progress-bar.mhtml".



-- 
"The angel of history[...]is turned toward the past." (Walter Benjamin)

------------------------------------------------------------------------------
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

Reply via email to