To implement a file upload progress bar, in an environment where we
normally use Mason, I had to use a classic CGI script so that I could
read the PATH_INFO and Content-Length headers even before the whole
request was received. I don't pretend to having created any kind of
optimal solution - but all the solutions that I've seen were working
in a similar way - there is a bare CGI or PHP script that saves the
file and the value of Content-Length - and then Ajax callbacks
compares the current size of the saved file with the Content-Length
header and computes the progress (it assumes that the file is much
bigger than the headers and that the percentage does not need to be
exact). There is also a need to pass the file name into that CGI
script - so that the file is saved into a location known to the Ajax
request I did that with PATH_INFO. In other words the file saving
script needs to know the values of some HTTP headers even before it
received all the query parameters - this is similar to the streaming
discussed in the "POST requests with a large body" thread. I've
described my solution at
http://perlalchemy.blogspot.com/2010/06/implementing-file-upload-progress-bar.html
Has anyone devised a way to do that in pure PSGI environment?
--
Zbigniew Lukasiak
http://brudnopis.blogspot.com/
http://perlalchemy.blogspot.com/
How do you get the value of a query_string in the sysread() loop?
This could be better then using the PATH_INFO as I suggested in my
post - but this is complicated by the fact that you need to parse the
query to get it and the 'normal' way to do that with Plack::Request
would not work here.
--
Zbigniew
> By the way, does anyone know of a front end proxy that handles
> this stuff before passing it on? so that your Plack back-end memory
> footprint is not tied up watching a long & super slow POST?
nginx http://wiki.nginx.org/NginxHttpUploadProgressModule
perlbal http://brad.livejournal.com/2171184.html
There should be a way to do the same with lighttpd or mod_proxy.
> On Oct 13, 6:03 pm, Zbigniew Lukasiak <zzb...@gmail.com> wrote:
>> On Wed, Oct 13, 2010 at 6:39 AM, jbjbjb <justinbe...@gmail.com> wrote:
>> > Hi,
>> > I did this today via hacking Starman Server.pm to hook into the
>> > sysread() loop which goes around once per TCP data packet, typically.
>> > It was quite an easy change and then the ajax upload progress checker
>> > can get the info it needs. I wrote the status to a file in /tmp named
>> > according to a query_string parameter value, so that the ajax call
>> > (which gets back JSON data) can get the right status if there are two
>> > or more posts going on simultaneously.
>>
>> How do you get the value of a query_string in the sysread() loop?
>> This could be better then using the PATH_INFO as I suggested in my
>> post - but this is complicated by the fact that you need to parse the
>> query to get it and the 'normal' way to do that with Plack::Request
>> would not work here.
>>
>> --
>> Zbigniew
--
Tatsuhiko Miyagawa