Python file upload

Bjarne Christiansen bjarne_christiansen at hotmail.com
Wed Jun 26 10:08:26 CEST 2002


Hi,
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 
missing....

Here is my file upload script:

#!c:\Python\python -d

import cgi

print "content-type: text/html\n\n"

form = cgi.FieldStorage()
if not form:
  print """
<form action="http://localhost/cgi-bin/upload.py" method="POST" 
enctype="multipart/form-data">
<input type="file" name="filename">
<input type="submit">
</form>
  """
elif form.has_key("filename"):
  item = form["filename"]
  if item.file:
    data = item.file.read()
    print cgi.escape(data)
    data1 = cgi.escape(data)
    f = open("file1.jpg","wb")
    f.write(data1)

Any help will be greatly appriciated!

Best Regards,
Bjarne Christiansen
bjarne_christiansen at hotmail.com


_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx






More information about the Python-list mailing list