1

I'm having difficulty finding out how to parse FormData with Python. I have base64_decoded my python string already as follows:

def lambda_handler(event, context):
    
    print(base64.b64decode(event['body']))
    # dict_obj = json.loads(base64.b64decode(event['body'])) #returns error

Now printing out the base64 decoded body prints out:

b'------WebKitFormBoundaryHFIqTxrMuAs5kep2\r\nContent-Disposition: form-data; name="username"\r\n\r\nTESTUSER\r\n------WebKitFormBoundaryHFIqTxrMuAs5kep2\r\nContent-Disposition: form-data; name="regionValue"\r\n\r\nreg\r\n------WebKitFormBoundaryHFIqTxrMuAs5kep2\r\nContent-Disposition: form-data; name="countryValue"\r\n\r\ncountry\r\n------WebKitFormBoundaryHFIqTxrMuAs5kep2\r\nContent-Disposition: form-data; name="gridValue"\r\n\r\ngrid\r\n------WebKitFormBoundaryHFIqTxrMuAs5kep2\r\nContent-Disposition: form-data; name="file1"; filename="Rate.csv"\r\nContent-Type: text/csv\r\n\r\nCluster Code,Pace Product Code...

This string contains the following information: (1) Multiple text fields (including a 'username' value), (3) two csv files in the string

How can I capture these variables from the string. I would preferably want my username as a variable and my file stored as a pandas dataframe.

Any Tips?

2
  • you might be looking for the solution explained here this Commented Feb 6, 2023 at 4:54
  • 1
    @eswar I did try and copy that code into my lambda function but I still seem to be getting an error: [ERROR] KeyError: 'boundary' Commented Feb 6, 2023 at 5:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.