Upload of binary files

Peter Mott peter.mott at btconnect.com
Wed Mar 12 19:35:15 CET 2003

I am having problems with uploading binary files. I have searched the
archives and found my problem several times but no answers. The problem is
that this little form:

<form action="http://in24/cgi-bin/upload.py" method="post"
Title: <input type="text" name="Title"><br>
File: <input type="file" name="Image"><br>
<input type="submit" value="-OK-">

with my very standard Python script at the other end will only work for
ascii files. With a binary file only a fragment is uploaded.

The Python is:

if form.has_key("Image"):
    tmp = open("C:/temp/temporary.dat","wb")
    while 1:
        line = fileinfo.file.readline()
        if not line: break
        lines += 1


which I have copied from various sources (and tried several variants). One
surprising thing is that a .png file uploads %PNG and no more.  This is
Python 2.2.1c2 on Windows 2000 with Apache 1.3.24 for Windows. I'm using
localhost under various names.

Any comments appreciated


More information about the Python-list mailing list