{"id":15971,"library":"aws-lambda-multipart-parser","title":"AWS Lambda Multipart Form Data Parser","description":"This library provides a specialized parser for `multipart/form-data` requests specifically designed for AWS Lambda environments. Unlike general-purpose server-based parsers, `aws-lambda-multipart-parser` is tailored to work within the constraints of serverless functions and the particular event structure provided by AWS API Gateway. It takes the raw `event` object from a Lambda invocation and processes its `body` to extract form fields and uploaded files, returning a structured JavaScript object. The current stable version, 0.1.3, indicates a very early stage of development, and the project appears to be abandoned, with no significant updates or commits in several years. Its primary differentiator was its early focus on simplifying `multipart/form-data` handling for AWS Lambda at a time when native support was less mature, abstracting away the complexities of binary media types, base64 encoding, and API Gateway proxy integration nuances.","status":"abandoned","version":"0.1.3","language":"javascript","source_language":"en","source_url":"https://github.com/myshenin/aws-lambda-multipart-parser","tags":["javascript","aws","lambda","multipart","multipart/form-data","multipart/formdata","form-data","formdata","parser"],"install":[{"cmd":"npm install aws-lambda-multipart-parser","lang":"bash","label":"npm"},{"cmd":"yarn add aws-lambda-multipart-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add aws-lambda-multipart-parser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library is CommonJS-only and does not natively support ESM import syntax.","wrong":"import parse from 'aws-lambda-multipart-parser';","symbol":"parse","correct":"const parse = require('aws-lambda-multipart-parser');"},{"note":"While `parse` is the primary export, destructuring from `require` is common. ESM named imports are not supported.","wrong":"import { parse } from 'aws-lambda-multipart-parser';","symbol":"parse","correct":"const { parse } = require('aws-lambda-multipart-parser');"}],"quickstart":{"code":"const multipart = require('aws-lambda-multipart-parser');\n\nexports.handler = (event, context, callback) => {\n    // Ensure API Gateway is configured for binary media types and Lambda Proxy Integration.\n    // The 'spotText' parameter can be set to true to have text files returned as strings.\n    const parsedBody = multipart.parse(event, true);\n\n    // Example of accessing a field and a file\n    console.log('Form field value:', parsedBody.field);\n    if (parsedBody.file) {\n        console.log('File:', parsedBody.file.filename, parsedBody.file.contentType);\n        // If spotText is true, content of text files is a string\n        console.log('File content (text):', parsedBody.file.content);\n    }\n\n    const response = {\n        statusCode: 200,\n        headers: {\n            \"Access-Control-Allow-Origin\": \"*\", // Essential for CORS if frontend is different origin\n            \"Content-Type\": \"application/json\"\n        },\n        body: JSON.stringify({\n            message: \"Successfully parsed multipart data\",\n            data: parsedBody // Be careful exposing raw parsed data, especially buffers\n        })\n    };\n\n    callback(null, response);\n};","lang":"javascript","description":"Demonstrates parsing an AWS Lambda event containing multipart/form-data and returning a structured JSON response, including necessary CORS headers."},"warnings":[{"fix":"Consider using newer, actively maintained libraries like `busboy` or implementing custom parsing logic with current Node.js APIs, or leveraging API Gateway's direct integration features for file uploads if applicable.","message":"This library is effectively abandoned, with no updates or commits in over six years. It may not be compatible with newer Node.js runtimes (e.g., Node.js 18+), latest AWS Lambda features, or API Gateway configurations. Modern alternatives should be preferred.","severity":"breaking","affected_versions":">=0.1.3"},{"fix":"Ensure your API Gateway method's 'Integration Request' for your Lambda function has 'Use Lambda Proxy Integration' checked, or set `integration: LAMBDA` if using Serverless Framework.","message":"When integrating with API Gateway, it is crucial to set `integration: LAMBDA` in your `serverless.yml` or enable 'Use Lambda Proxy Integration' in the API Gateway console. Failing to do so will result in '502 Bad Gateway' errors.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Add `\"Access-Control-Allow-Origin\": \"*\"` (or specific origin) to the `headers` object of your Lambda's response.","message":"Default API Gateway CORS configurations do not always work correctly with `LAMBDA` integration for `multipart/form-data`. You must manually include `Access-Control-Allow-Origin` headers in your Lambda function's response.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"When returning file content in a JSON response, convert `Buffer` objects to a base64 string (e.g., `file.content.toString('base64')`). Ensure the client knows how to decode it.","message":"The library returns file contents as Node.js `Buffer` objects by default for non-text files. If `spotText` is `true`, text files are returned as strings. Handling binary buffers correctly (e.g., converting to base64 for JSON responses) is crucial.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"In API Gateway console, for your POST method's 'Integration Request', check 'Use Lambda Proxy Integration'. If using Serverless Framework, add `integration: LAMBDA` to your function's HTTP event configuration.","cause":"API Gateway is not configured for Lambda Proxy Integration, or `integration: LAMBDA` is missing in Serverless Framework configuration.","error":"502 Error: Bad Gateway"},{"fix":"Include `headers: { \"Access-Control-Allow-Origin\": \"*\" }` (or your specific frontend origin) in your Lambda function's response object.","cause":"Your Lambda function's response is missing the `Access-Control-Allow-Origin` header required for cross-origin requests.","error":"Access to XMLHttpRequest at '...' from origin '...' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource."}],"ecosystem":"npm"}