Cgi.parse_multipart or FieldStorage to parse multipart-formdata in AWS Lambda?



I see several questions about how to upload form data including files to AWS Lambda e.g. :

The way I do it now is the following

def import_collection(event, context):
s3 = boto3.resource(‘s3’)
print(“importing collection”)
c_type, c_data = parse_header(event[‘headers’][‘content-type’])
c_data[‘boundary’] = bytes(c_data[‘boundary’], ‘utf8’)
body_file = BytesIO(bytes(event[‘body’], ‘utf8’))
form_data = parse_multipart(body_file, c_data)
data = form_data[‘file’][0].decode(‘UTF-8’)
culture = form_data[‘culture’][0].decode(‘UTF-8’)
collection = form_data[‘collection’][0].decode(‘UTF-8’)
format = form_data[‘format’][0].decode(‘UTF-8’)

Is the above ok, should I use cgi.Fieldstorage instead, or some other way?

In the following thread at SO I see that it is advised to use cgi.FieldStorage instead of parse_multipart:

Can you provide me with more information? I don’t need to upload binary/image files, only test files. But it would be nice if I could also get the file name.