1. clach04
  2. woof

Commits

clach04  committed 72e3765 Draft

Upload of binary files resulted in corrupted files under Windows.

  • Participants
  • Parent commits b926650
  • Branches default

Comments (0)

Files changed (1)

File woof.py

View file
       for suffix in ["", ".1", ".2", ".3", ".4", ".5", ".6", ".7", ".8", ".9"]:
          destfilename = os.path.join (".", upfilename + suffix)
          try:
-            destfile = os.open (destfilename, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0644)
+            destfile = os.open (destfilename, os.O_BINARY |os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0644)
             break
          except OSError, e:
             if e.errno == errno.EEXIST:
 
       print >>sys.stderr, "accepting uploaded file: %s -> %s" % (upfilename, destfilename)
 
-      shutil.copyfileobj (upfile.file, os.fdopen (destfile, "w"))
+      shutil.copyfileobj (upfile.file, os.fdopen (destfile, "wb"))
       
       if upfile.done == -1:
          self.send_error (408, "upload interrupted")