WebKit Examples

Upload Test

This servlet shows how to handle uploaded files. The process is fairly self explanatory. You use a form like the one below in the writeContent method. When the form is uploaded, the request field with the name you gave to the file selector form item will be an instance of the FieldStorage class from the standard Python module "cgi". The key attributes of this class are shown in the example below. The most important things are filename, which gives the name of the file that was uploaded, and file, which is an open file handle to the uploaded file. The uploaded file is temporarily stored in a temp file created by the standard module. You'll need to do something with the data in this file. The temp file will be automatically deleted. If you want to save the data in the uploaded file read it out and write it to a new file, database, whatever.