Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const Busboy = require('busboy');
const busboy = require('busboy');

/*
* This module will parse the multipart-form containing files and fields from the lambda event object.
Expand All @@ -21,7 +21,7 @@ const Busboy = require('busboy');
}
*/
const parse = (event) => new Promise((resolve, reject) => {
const busboy = new Busboy({
const bb = busboy({
headers: {
'content-type': event.headers['content-type'] || event.headers['Content-Type']
}
Expand All @@ -30,7 +30,7 @@ const parse = (event) => new Promise((resolve, reject) => {
files: []
};

busboy.on('file', (fieldname, file, filename, encoding, mimetype) => {
bb.on('file', (name, file, info) => {
const uploadFile = {};

file.on('data', data => {
Expand All @@ -39,31 +39,31 @@ const parse = (event) => new Promise((resolve, reject) => {

file.on('end', () => {
if (uploadFile.content) {
uploadFile.filename = filename;
uploadFile.contentType = mimetype;
uploadFile.encoding = encoding;
uploadFile.fieldname = fieldname;
uploadFile.filename = info.filename;
uploadFile.contentType = info.mimeType;
uploadFile.encoding = info.encoding;
uploadFile.fieldname = name;
result.files.push(uploadFile);
}
});
});

busboy.on('field', (fieldname, value) => {
result[fieldname] = value;
bb.on('field', (name, val, info) => {
result[name] = val;
});

busboy.on('error', error => {
bb.on('error', error => {
reject(error);
});

busboy.on('finish', () => {
bb.on('finish', () => {
resolve(result);
});

const encoding = event.encoding || (event.isBase64Encoded ? "base64" : "binary");

busboy.write(event.body, encoding);
busboy.end();
bb.write(event.body, encoding);
bb.end();
});

module.exports.parse = parse;
Loading