[mod_python] Upload progress indicator shows after upload?

Martijn martijn at xs4us.nu
Thu Jul 31 05:17:20 EDT 2008


Hi,

I would suggest a few things.

In stead of images I would use a DIV with either a background image (use CSS 
repeat and a n imagewitdh of 1) with that you can make a nice progressbar)

Next you need to req.write and req.flush in your while bytes_left loop 
otherwise no updates are send to the browser. you can send something like:
"<script>window.parent.getElementById('yourdiv').style.width=(maxwidth/100)*[yourcalculatedwith]</script>"
(this example is an indication it has to be checked) 

On the broser site, you can do a lot of things but I suggest using a hidden 
iframe where you set the target of the upload to...
You can also choose to put the progessbar in the Iframe, and do a "show" 
before the submit. Right after you can send another script to hide it again 
or make the iframe dissappear when it finished loading (by sending something 
right after the upload started: <script 
defer=true>window.parent.getElementById('YourIframe').visable=false</script>
the defer=true will make it run after all the the page finished loading 

I used different ways to make a progressbar in different projects all is 
depending on how you organise things in your site. The req.write en even more 
important the req.flush in the loop should do the trick.

All the other stuff is not Mod_python related.

Martijn


On Wednesday 02 August 2006 01:14, jadacyrus 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


More information about the Mod_python mailing list