# Cgi.parse\_multipart or FieldStorage to parse multipart-formdata in AWS Lambda?

**URL:** <https://forum.serverless.com/t/cgi-parse-multipart-or-fieldstorage-to-parse-multipart-formdata-in-aws-lambda/6888>\
**Category:** Serverless Framework\
**Tags:** aws, lambda\
**Created:** [January 4, 2019, 9:14am UTC](https://forum.serverless.com/t/cgi-parse-multipart-or-fieldstorage-to-parse-multipart-formdata-in-aws-lambda/6888 "2019-01-04T09:14:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![montao](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/montao/32/3525_2.png) [@montao](https://forum.serverless.com/u/montao)\
**Post date:** [January 4, 2019, 9:14am UTC](https://forum.serverless.com/t/cgi-parse-multipart-or-fieldstorage-to-parse-multipart-formdata-in-aws-lambda/6888/1 "2019-01-04T09:14:29Z")

</div>

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

> [@Endpoint for file upload (API gateway + Lambda + Python)](http://forum.serverless.com/t/endpoint-for-file-upload-api-gateway-lambda-python/908):
>
> Hi, I’m pretty new to Serverless so please excuse the stupid question. I have a POST endpoint configured with lambda-proxy and working fine with some test data (path variables and query variables are read correctly and so on). The next step is actually to use the endpoint to upload a file the way my current Flask app works (i.e. with a standard request such as curl --form "catalogue=@FILE\_NAME.zip" ENDPOINT ). However I cannot seem to find a way to code the endpoint so that you can upload a…

The way I do it now is the following

def import\_collection(event, context):  
s3 = boto3.resource(‘s3’)  
print(“importing collection”)  
#print(event[‘queryStringParameters’][‘filename’])  
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)  
print(“form\_data:”)  
print(str(form\_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:

> <https://stackoverflow.com/questions/3380501/how-can-i-find-out-the-uploaded-file-name-in-python-cgi>

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.
