Problems with uploading binary files using cgi module

Shichang Zhao shichang at icubed.com
Mon Mar 6 12:02:09 EST 2000


It can not be more helpful if you could send me the code. 

I shall apologize to Guido, for bothering him on this topic.

-----Original Message-----
From:	x at x.x [SMTP:x at x.x]
Sent:	Monday, March 06, 2000 9:50 PM
To:	python-list at python.org
Subject:	Re: Problems with uploading binary files using cgi module

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:
> 
> Goal:
>      Uploading a binary file, say a Microsoft Word file name test.doc, to 
> Web server's cgi-bin directory with a name
>      tmp.doc.
:
> 
> 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
uploaded.

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.
-- 
http://www.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list