[mod_python] Re: File/Image upload

Benjamin Niemann b.niemann at betternet.de
Thu Jul 8 10:53:24 EDT 2004

Victor Tortorello Neto wrote:
> Hello!
> I'm trying to upload an image to server. I was trying on Windows, opening an 
> "fd" and writing image content in the fd.
> I don't know if it's the best way to do this, if you know a better way please 
> tell me! :)
> Everything happens ok with Windows, open the fd with os.O_BINARY flag.
> Today I have to migrate the web site to Linux, and only image upload has a 
> problem, this problem.
> Well, my question is:
> Has some flag equivalent to Windows O_BINARY on Linux?
Not really. Using O_BINARY won't hurt and is good practice to avoid 
problems when moving from UNIX style systems to windows. UNIX style 
systems - including Linux - always treat a file as binary data.

> And my error output:
> IOError: image file is truncated (30 bytes not processed)
When you try to open the uploaded file for reading? Is the file created 
at all?
A common problem for UNIX newcomers (and fileuploads through webservers 
in general) are access restrictions for the directory where the files 
are stored. Is the user, the webserver is running under (often something 
like www or www-data), allowed to write to the directory? Try "chmod a+w 
dirname". If this works, look for more info about UNIX users, groups and 
permissions and find some working but more restrictive settings (a+w 
grants write access to everyone..).

More information about the Mod_python mailing list