[mod_python] File upload

Maria Gomez mgomez at aditel.org
Thu Sep 18 10:04:57 EST 2003

On Wed, Sep 17, 2003 at 09:42:47PM -0700, Greenbeard wrote:
> Does anyone have a good file upload example?  
> When I try something like: 
> def upload(req, file):
>     tempFile = file.read()


   I use to do it as follows:

def CheckingUploadedFile(incoming):
    if incoming is None:
        return 0     # File is empty
    if type(incoming) is str:
        return 0     # File is a string
    return 1

def PrepareFile(file):
        Copies uploaded file in a local directory (CACHE_DIR) and names
		it with its md5, whish is almost unique
    aux = file.read()
    md5_n = "name_of_file"
    cache_file = "%s%s" % (cache_dir , md5_n)
    cache_fd = open(cache_file,'w')
    return 1

def Upload(req,incoming):
    if CheckingUploadedFile(incoming):
        #Save file(incoming.file) in the proper directory
		return 1
		print "There was an uploading error"

   To know more the updated structure of the file is:
['__del__', '__doc__', '__getattr__', '__init__', '__module__',
'__repr__', 'disposition', 'disposition_options', 'file', 'filename',
'headers', 'name', 'type', 'type_options']


   Maria Gomez Marti - [octal]

=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* Linux, porque yo lo valgo 

More information about the Mod_python mailing list