I have a string like this
\"--5b34210d81fb44c5a0fdc1a1e5ce42c3\\r\\nContent-Disposition: form-data; name=\\\"author\\\"\\r\\n\\r\\nJohn Smith\\r\\n--5b34210d
Had a bunch of weird encoding issues and also odd behavior with api gateway, originally received the body of the request at bytes and then after redeploying started to receive them as base64. Anyway this is the code that ended up working for me.
import json
import base64
import boto3
from requests_toolbelt.multipart import decoder
s3client = boto3.client("s3")
def lambda_handler(event, context):
content_type_header = event['headers']['content-type']
postdata = base64.b64decode(event['body']).decode('iso-8859-1')
imgInput = ''
lst = []
for part in decoder.MultipartDecoder(postdata.encode('utf-8'), content_type_header).parts:
lst.append(part.text)
response = s3client.put_object( Body=lst[0].encode('iso-8859-1'), Bucket='test', Key='mypicturefinal.jpg')
return {'statusCode': '200','body': 'Success', 'headers': { 'Content-Type': 'text/html' }}