Created
July 24, 2019 19:14
-
-
Save kgriffs/7db18102a2051cfaa60503638d3af673 to your computer and use it in GitHub Desktop.
Falcon: Multipart form parsing example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cgi | |
# NOTE: This does not handle file uploads | |
def parse_form(req): | |
# NOTE: See also the docs for cgi.FieldStorage | |
form = cgi.FieldStorage(fp=req.stream, environ=req.env, | |
keep_blank_values=1) | |
if not form.list: | |
return {} | |
# NOTE(kgriffs): This assumes you are not expecting duplicate fields | |
# with the same name. | |
return {field.name: field.value for field in form.list} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for your idea.