lambda-multipart

A simple multipart/form-data parser for AWS lambda functions.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
lambda-multipart
1521.0.26 years ago6 years agoMinified + gzip package size for lambda-multipart in KB

Readme

lambda-multipart
A simple multipart/form-data parser for AWS lambda functions.
npm install -S lambda-multipart

var Multipart = require('lambda-multipart');

exports.handler = function(event, context, callback){

  var parser = new Multipart(event);

  parser.on('field',function(key, value){
    console.log('received field', key, value);
  });
  parser.on('file',function(file){
    //file.headers['content-type']
    file.pipe(fs.createWriteStream(__dirname+"/downloads/"+file.filename));
  });

  parser.on('finish',function(result){
    //result.files (array of file streams)
    //result.fields (object of field key/values)
    console.log("Finished")
  });
}

AWS Setup

There is a small bit of setup on the AWS side. Head to the API Gateway service you want to setup and select:
Settings > Binary Media Types
Add a new entry for multipart/form-data
Screenshot

Credits and Acknowledgements

  • @hapijs for https://github.com/hapijs/pez
  • @myshenin for https://github.com/myshenin/aws-lambda-multipart-parser