Skip to Content
Modern Python Standard Library Cookbook
book

Modern Python Standard Library Cookbook

by Alessandro Molina
August 2018
Intermediate to advanced
366 pages
10h 14m
English
Packt Publishing
Content preview from Modern Python Standard Library Cookbook

How it works...

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Advanced Python Development: Using Powerful Language Features in Real-World Applications

Advanced Python Development: Using Powerful Language Features in Real-World Applications

Matthew Wilkes

Publisher Resources

ISBN: 9781788830829Supplemental Content