[mod_python] Upload progress indicator shows after upload?

jadacyrus jadacyrus at gmail.com
Wed Aug 2 20:51:37 EDT 2006

Graham Dumpleton wrote:
> Colin Bean wrote ..
>> Unfortunately, what you're trying to do is more complicated than this.
>>  First of all, by the time your handler is called, the file has
>> already been sent over the network, and your handler is only reading
>> it from a tempfile on disk.  Also, a handler only sends one response
>> back after running to completion, so your code is behaving as
>> expected.  It finishes processing the file upload (including doing
>> everything in your loop), and when it's finished it sends a response
>> back to the client.
>> Sorry I can't provide more constructive feedback having never actually
>> implemented something like this.  To take a guess at it, you'd need to
>> use an InputFilter to examine the upload request as it is read (I
>> believe this phase happens before the tempfile is written to disk),
>> and this would need to somehow communicate with another mod_python
>> handler which would return the current upload progress.  The client
>> page wold have to keep polling this handler (with an XMLHttpRequest,
>> perhaps) and display the results it gets with each poll.  Yeah, it's
>> pretty ugly...
> Except that a subsequent request to try and monitor progress may in a multi
> process version of Apache end up at a different process and will not have
> access to where the original request is up to.
> In short, there are many reasons why a progress meter is hard to implement and
> may not even give a correct indication of what is happening anyway.
> Personally, I am not sure what the fascination is with them besides the eye
> candy value of it.
> Graham
>> HTH,
>> Colin
>> On 8/1/06, jadacyrus <jadacyrus at gmail.com> wrote:
>>> Essentially this is what I have setup for my upload script:
>>> [code]
>>> #HTML Stuff here
>>> #Declare variables etc...
>>>     while bytes_left >= 0:
>>>             fileData = req.form['filename'].file.read(1024)
>>>             filebuffer = filebuffer + fileData
>>>             bytes_left = bytes_left - 1024
>>>             bytes_read = bytes_read + 1024
>>>             percent = bytes_read/int(length) * 100
>>> #Some nested IF statements to display a progress indicator using images
>>> based on the percent variable.
>>> [/code]
>>> This is contained in my upload.py in the function upFile which is called
>>> from the POST method. However, It seems that the file uploads completely
>>> first and then it will show the progress indications afterwards. However
>>> this doesn't seem to be logically what my code should be doing. I'm
>>> somewhat new to mod_python but not python in general, any suggestions?
>>> _______________________________________________
>>> Mod_python mailing list
>>> Mod_python at modpython.org
>>> http://mailman.modpython.org/mailman/listinfo/mod_python
>> _______________________________________________
>> Mod_python mailing list
>> Mod_python at modpython.org
>> http://mailman.modpython.org/mailman/listinfo/mod_python
Hmm, well it was more of a thing just to let people who are using my 
site know that the file is actually being uploaded. I guess it really 
isnt that necessary however. Thanks for all the responses and information.

More information about the Mod_python mailing list