📜  解码多部分表单数据 python lambda - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:37.233000             🧑  作者: Mango

代码示例1
import cgi
import io

def handler(event, context):
    print(event)
    print(event['body'])

    fp = io.BytesIO(event['body'].encode('utf-8'))
    pdict = cgi.parse_header(event['headers']['Content-Type'])[1]
    if 'boundary' in pdict:
        pdict['boundary'] = pdict['boundary'].encode('utf-8')
    pdict['CONTENT-LENGTH'] = len(event['body'])
    form_data = cgi.parse_multipart(fp, pdict)
    print('form_data=', form_data)