August 2018
Intermediate to advanced
366 pages
10h 14m
English
The application exposes two web pages. One is on the root of the website (through the index function) that only shows a simple form with an upload field.
The other, the upload function, instead receives the uploaded file and shows it back if it's an image or a text file. In all other cases, it will just show the name of the uploaded file.
All that is required to handle the upload in multipart format is to create a cgi.FieldStorage out of it:
form = cgi.FieldStorage(fp=req.environ['wsgi.input'],
environ=req.environ)
The whole body of the POST request is always available in the environ request with the wsgi.input key.
This provides a file-like object that can be read to consume the posted data. Make sure you save aside the ...