myshenin / aws-lambda-multipart-parser

Parser of multipart/form-data requests for AWS Lambda
MIT License
74 stars 38 forks source link

(HelpWanted) Reuse the binary to make a request #20

Open refucktor opened 6 years ago

refucktor commented 6 years ago

First of all, great job! this library help from having a hell of parsing multipart/form-data. I'm now facing a very strange situation, my lambda function it's just an interface between a client and an API, I'm using your library to parse the incoming data and, make some operations and then post a different object to the API. My function looks like this

const axios = require('axios');
const multipart = require('aws-lambda-multipart-parser');
module.exports.run = async event => {
    try {
        /* sample of json
            {name: 'test_a', something: 'test_b', documents: ''}
        */
        const data = multipart.parse(event, false);

        /* data.documents has the file(s) */
        const result = await someOperation(data);
        const response = axios.post('http://example.com/results', result);
        return {
            statusCode: 200,
        body: JSON.stringify(response.data),
        }
        } catch (e) {
            return {
                statusCode: 500,
            body: JSON.stringify({
                    message: e.message,
                    stack: e,
            }),
        }
    }
};

My problem is that I need to reuse the files to make the last request. So far I'm failing on every try and I will appreciate your help a lot! Any idea is more than welcome. Thanks in advance