Upload of binary files
peter.mott at btconnect.com
Thu Mar 13 08:58:28 CET 2003
Agreed - I copied the code, mine originally used read(). But read does not
fix it. Here is an even shorter script:
import cgitb; cgitb.enable()
form = cgi.FieldStorage()
data = fileinfo.file.read()
print "Content-type: text/plain\n\n"
Text files print their lengths. Graphic files truncate, one to 176 bytes
(actually 176, 177, 176, different each upload). Another gets 3323 bytes up.
A .png file mangages only 4. The HTML is:
Text File: <input type="file" name="Data"><br>
<input type="submit" value="-OK-">
"Levente Sandor" <sandorlevi at yahoo.com> wrote in message
news:8b5e42a6.0303121653.6d452403 at posting.google.com...
> "Peter Mott" <peter.mott at btconnect.com> wrote in message
news:<b4nul3$7d2$1 at knossos.btinternet.com>...
> > I am having problems with uploading binary files. I have searched the
> > while 1:
> > line = fileinfo.file.readline()
> It is _absolutely not_ a good idea to use the readline() method on binary
> Use the read() method instead, it should work.
More information about the Python-list