Parse multipart/form-data from body as string on AWS Lambda

后端 未结 4 1797
梦毁少年i
梦毁少年i 2020-12-14 17:55

I\'m glad to see AWS now supports multipart/form-data on AWS Lambda, but now that the raw data is in my lambda function how do I process it?

I see multiparty is a g

4条回答
  •  囚心锁ツ
    2020-12-14 18:34

    busboy doesn't work for me in the "file" case. It didn't throw an exception so I couldn't handle exception in lambda at all.

    I'm using aws-lambda-multipart-parser lib wasn't hard like so. It just parses data from event.body and returns data as Buffer or text.

    Usage:

    const multipart = require('aws-lambda-multipart-parser');
    
    const result = multipart.parse(event, spotText) // spotText === true response file will be Buffer and spotText === false: String
    

    Response data:

    {
        "file": {
            "type": "file",
            "filename": "lorem.txt",
            "contentType": "text/plain",
            "content": {
                "type": "Buffer",
                "data": [ ... byte array ... ]
            } or String
        },
        "field": "value"
    }
    

提交回复
热议问题