Problem while uploading a binary file using cgi module
jw9 at cse.buffalo.edu
Sun Feb 3 21:49:59 EST 2002
I test the script from
My problem is that it works fine with a text file, but failed everytime
with a binary file such as jpeg file, even a very small (5k) binary file.
I tried read(), readline(), readlines(). It just doesn't work. Every time
the FieldStorage() only read a very small portion of the binary file and
what have I done wrong? By the way, i need to use it in a webpage, so
ftplib module is not a alternative option.
the code is like this:
print 'Content-type: text/html\n'
form = cgi.FieldStorage()
if not form:
<form action="test.py" method="POST" enctype="multipart/form-data">
<input type = "file" name = "filename">
<input type ="submit">
item = form["filename"]
data = item.file.readline()
fp = file('1.jpg','wb')
More information about the Python-list