Problems with uploading binary files using cgi module
shichang at icubed.com
Sun Mar 5 22:51:22 CET 2000
I am not sure there is a bug in Python cgi module or I did something wrong.
Here is what I am trying to achieve:
Uploading a binary file, say a Microsoft Word file named test.doc, to
Web server's cgi-bin directory with a name
form = cgi.FieldStorage(keep_blank_values=1, strict_parsing=1)
fileitem = form["UPL_1"] #UPL_1: The file name given in HTML form
filename = fileitem.filename
f = open("tmp.doc", "wb")
filename = ""
print "Content-type: text/html\n\n"
After the file is uploaded, I compared the original file's size (19,456
bytes) with the file saved onto the server's cgi-bin directory (tmp.doc,
size: 13,073 bytes). Some of the bytes are lost after the file is uploaded.
I searched Python's web site and dejanews web site, no where I can get an
answer. Please point out what I have done wrong, and how to correct the
Any suggestions/hints would be very helpful.
More information about the Python-list