CGI File Upload

Bill Seitz fluxent at
Wed Dec 6 19:23:16 CET 2000

In article <ulmttsihs.fsf at>,
  piet at wrote:
> >>>>> Bill Seitz <fluxent at> (BS) writes:
> BS> Hmm, this works for me with text data (though the file length is
> BS> slightly different: maybe line-end changes from Win to *nix?).
> BS> binary it's totally off. Uploading a JPEG I consistently only get
> BS> bytes written to the file system. With GIFs I consistently get
> BS> bytes (but not always exactly the same number). With an MsWord
file I
> BS> get a bigger file written, but still not the whole thing (60kb
out of
> BS> 75kb).
> BS> What do I do next?
> Is your server on Windows? Then it probably is a matter of the
> input being in text mode rather than binary mode.
> So you have to set it to binary mode before anything is read from it.
> See msvcrt.setmode()

Yes, this turned out to be the issue. I had it set for stdout, but not

msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)

Sent via
Before you buy.

More information about the Python-list mailing list