Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Ground Controller Lvl 1
Message 1 of 1

AWS Lambda Python 3 handle POST file

I'm working with Python 3.8 on AWS Lambda, and I would like to handle posted file, like requests.files with Django. But it's impossible with AWS Lambda. I want to put this file in the S3 with :

s3.put_object(
    Body=fileAsString,
    Bucket=MY_BUCKET,
    Key='my-file.jpg'
)


When I return directly the received event, with the file :CKeMs
I tried with cgi.parse_multipart; in my handler :

c_type, c_data = parse_header(event['headers']['Content-Type'])
boundary = c_data['boundary'].encode('latin1')
body = event['body'].encode('utf8')
 
fp = BytesIO(body)
pdict = {
    'boundary': boundary,
    'CONTENT-LENGTH': str(len(body))
}
form_data = parse_multipart(fp, pdict)
fileBytes: bytes = form_data['file'][0]
return ({'statusCode': 200, 'file': json.dumps(str(fileBytes))}


I receive :zCrmK

I also tried with

form_data['file'][0].decode('utf-8')

but I receive :

CkfMM

and I have always the "?"

I should get this, because it's the original image, opened in edition :

20MMR


Any idea ?