http file post

D

Dave

Greetings.

Ive been trying to figure out how I can write to a file from an HTTP
post while it is being uploaded. So far ive realized that my script
isn't getting the data until the browser is done uploading. What I want
to accomplish is a way to track the progress of a file upload. I'm
guessing that if I can get it to write to a file as it is uploaded I can
load another browser to check the progress of the transfer (by refreshing).

Here is the general idea I have tried:

if item.file:
filen = item.filename
filen1 = filen.split('\\')
filen2 = filen1[len(filen1)-1]
outfile = open(path + filen2 + '.tmp','wb')
buff = item.file.read(40000)
while buff != "":
outfile.write(buff)
buff = item.file.read(40000)
if not buff:
break

Works, but I recieve the data all at once rather then while..

Perhaps it is my ignorance about how http works and that there is no
other way?

Thanks in advance.
-Dave
 
T

Tim Roberts

Dave said:
Ive been trying to figure out how I can write to a file from an HTTP
post while it is being uploaded. So far ive realized that my script
isn't getting the data until the browser is done uploading. What I want
to accomplish is a way to track the progress of a file upload.

This IS possible, but you'll have to do some work.

I assume this is a CGI script, and that you're using cgi.FieldStorage() to
fetch the POST contents. The key problem for you is that
cgi.FieldStorage() (and, more specifically, cgi.FieldStorage.read_binary)
does not return until the entire transmission is complete.

Now that you know that, your path should be clear: all you need to do is
make your own custom version of FieldStorage that updates a status variable
somewhere. Piece of cake!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,049
Members
47,655
Latest member
eizareri

Latest Threads

Top