mike_verdone at shaw.ca
Sat May 10 15:51:05 EST 2003
Here you go! Files sent to an Apache server via an HTTP request appear as file-like objects to mod_python. They support the read() method to get their contents. Assuming you're running the publisher handler, this function can receive the contents of a file sent by a user in an HTTP request (where the file's field is named "file"). def getFile(req, file=None): if file is None: # There was no file sent. return "Error! There was no file!" if type(file) is str: # File was sent as a regular field, which is bad. return "Error! File was a string!" fileData = file.read() # Get the file data into a Python variable. # ... process file data ... return "Ok, file received." The HTML that calls this function is as follows. Not the enctype attribute of the form tag. <form action="getFile" method="post" enctype="multipart/form-data"> <input type="file" name="file" /> <input type="submit" name="submit" value="Submit" /> </form> Could someone who knows the FAQ password please add this, if it's useful. Thanks. Mike. On May 10, 2003 09:52 am, Jonas Geiregat wrote: > I'm looking on how to upload a file in mod_python are there any examples ?