Problems with uploading binary files using cgi module
x at x.x
x at x.x
Mon Mar 6 22:50:11 CET 2000
In article <01BF86EC.F2D432E0.shichang at icubed.com>,
Shichang Zhao <shichang at icubed.com> wrote:
> I am not sure there is a bug in Python cgi module or I did somethin wrong.
> Here is what I am trying to achieve:
> Uploading a binary file, say a Microsoft Word file name test.doc, to
> Web server's cgi-bin directory with a name
> After the file is uploaded, I compared the original file's size (19,456
> bytes) with the file saved onto the server's cgi-bin directory (tmp.doc,
> size: 13,073 bytes). Some of the bytes are lost after the file is
Are you by any chance running this off a Windows server? I'm thinking
because you mentioned Microsoft Word; if so, I think I know what the
problem is: Standard input is opened by default in "text" mode, and
you're probably running into an end-of-file character (ascii 26) and
that's causing the file to truncate.
If that's the case, you're going to need to dig into the msvcrt module
and reset sys.stdin at the beginning of your cgi script. If I recall,
you need the "OSF handle" functions. I had to do that once, I can
dig up the code if you need it.
I do remember that doing an os.fdopen(0, "rb") wouldn't do it in
Win32. It was necessary to get into the msvcrt.dll gunk.
More information about the Python-list