Python file upload
R.Barrett at ftel.co.uk
Wed Jun 26 04:56:33 EDT 2002
I think you will find that your calls to cgi.escape the incoming data are
the cause of your problem.
You do not need to escape incoming multipart/form data. The documentation
for cgi.escape says:
Use this if you need to display text that might contain such characters in HTML
which is clearly not your purpose in handling the incoming data,
particularly when it is binary data.
At 08:08 26/06/2002 +0000, Bjarne Christiansen wrote:
>I have some problems uploading binary files though the web browser. It
>seens to work fine when uploading ACII file but but binary files seems to
>be currupted. The begining of the binary file seems fine, but some data is
>Here is my file upload script:
>print "content-type: text/html\n\n"
>form = cgi.FieldStorage()
>if not form:
> print """
><form action="http://localhost/cgi-bin/upload.py" method="POST"
><input type="file" name="filename">
> item = form["filename"]
> if item.file:
> data = item.file.read()
> print cgi.escape(data)
> data1 = cgi.escape(data)
> f = open("file1.jpg","wb")
>Any help will be greatly appriciated!
>bjarne_christiansen at hotmail.com
>MSN Photos is the easiest way to share and print your photos:
More information about the Python-list