CGI POST binary file upload?

Bill Seitz fluxent at yahoo.com
Tue Dec 5 12:28:10 EST 2000


I've tweaked some code which someone else posted a while back, to allow
a CGI (behind Apache on Win2K) accept a POST with a file upload, and
write it out to the file tree.

It works fine for text/html files (though the byte count is slightly
off: line endings?). But for binary files it's a total mess. For GIFs I
generally only get ~100 bytes, for JPEGs ~500bytes. MsWord and PDF
files also don't work, though I usually get a bigger end result.

I don't think the problem is the file writing, it's the
receiving/reading. I say this because I also output in my response page
len(data['image'].value)
and it agrees with the size of the output file.

I tried adding
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
up at the top of my code, but (a) it doesn't seem to matter, and (b)
I'm not sure whether I'm doing it right.

thx


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list