如何在Python中解析多部分表单数据

时间:2018-03-08 09:28:25

标签: python upload

我正在使用AWS API Gateway上传多个文件,如csv,txt。网关后面有一个pyhon Lambda。我得到如下的多部分响应。我想知道如何获取这些文件的内容并上传到S3

----------------------------124218046032878137249340
Content-Disposition: form-data; name="file1"; filename="2.csv"

Content-Type: text/csv

header,value

a,1
b,2

----------------------------124218046032878137249340

Content-Disposition: form-data; name="file2"; filename="1.txt"

Content-Type: text/plain

aa
bb
cc

----------------------------124218046032878137249340--

代码: -

def lambda_handler(event, context):

    print(event)
    my_body = event['body-json']
    decoded_body = base64.b64decode(my_body)
    my_multipart = str(decoded_body, 'utf-8')

0 个答案:

没有答案