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() > Hi, 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') cache_fd.write(aux) cache_fd.close() return 1 def Upload(req,incoming): if CheckingUploadedFile(incoming): #Save file(incoming.file) in the proper directory PrepareFile(incoming.file) return 1 else: 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'] Cheers, -- Maria Gomez Marti - [octal] =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* http://www.aditel.org/~mgomez =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* Linux, porque yo lo valgo
|