blob: d81a8f06e2c3dd243f547337c7d23c7a60d3866d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#!/usr/bin/python3
import python-multipart
import sys
import os
fields = {}
files = {}
def on_field(field):
fields[field.field_name] = field.value
def on_file(file):
files[file.field_name] = {'name': file.file_name, 'file_object': file.file_object}
with open ("multipart", mode='rb') as file:
form = file.read()
multipart_headers = {'Content-Type': os.environ['CONTENT_TYPE']}
multipart_headers['Content-Length'] = os.environ['CONTENT_LENGTH']
multipart.parse_form(multipart_headers, form, on_field, on_file)
print(fields)
print(files)
|