CGI File Upload

Mitchell Garnaat mitch at garnaat.com
Wed Dec 6 14:29:06 CET 2000


It sounds like you are on a PC platform and the input file is not being
opened in binary mode.  The default on Windows platforms is to open the file
in text mode.  When you hit the first zero byte in the binary file it will
be interpreted as an end-of-file.  Look in the CGI code to see where it is
opening files and make sure they are being opened in binary mode.

Mitch


"Bill Seitz" <fluxent at yahoo.com> wrote in message
news:90j10o$5p5$1 at nnrp1.deja.com...
> In article <8u7fn7$jpf$1 at la-mail4.digilink.net>,
>   "Pete Shinners" <pete at visionart.com> wrote:
> > "Simon Faulkner" <news at titanic.co.uk> wrote
> > > I would like users to be able to upload .jpeg files via a web page
> > > <input type=file>
> > >
> > > What python code do I need to be able to save the file to a
> directory
> > > on the hard disk?
> >
> > i have some code that does this.. you'll probably want to clean
> > it to suit your own purposes, but here it is. at some point i
> > wanted to add PIL support to resize the images to a certain
> > resolution and convert them to be JPG, but that day hasn't come
> > yet... heh. note it also allows the user to save a comment as a
> > .TXT file. anyways, you can use it as a start for whatever you want
>
> Hmm, this works for me with text data (though the file length is
> slightly different: maybe line-end changes from Win to *nix?). With
> binary it's totally off. Uploading a JPEG I consistently only get 109
> bytes written to the file system. With GIFs I consistently get ~500
> bytes (but not always exactly the same number). With an MsWord file I
> get a bigger file written, but still not the whole thing (60kb out of
> 75kb).
>
> What do I do next?
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.





More information about the Python-list mailing list