11'use strict' ;
22
3- const Busboy = require ( 'busboy' ) ;
3+ const busboy = require ( 'busboy' ) ;
44
55/*
66 * This module will parse the multipart-form containing files and fields from the lambda event object.
@@ -21,7 +21,7 @@ const Busboy = require('busboy');
2121 }
2222 */
2323const parse = ( event ) => new Promise ( ( resolve , reject ) => {
24- const busboy = new Busboy ( {
24+ const bb = busboy ( {
2525 headers : {
2626 'content-type' : event . headers [ 'content-type' ] || event . headers [ 'Content-Type' ]
2727 }
@@ -30,7 +30,7 @@ const parse = (event) => new Promise((resolve, reject) => {
3030 files : [ ]
3131 } ;
3232
33- busboy . on ( 'file' , ( fieldname , file , filename , encoding , mimetype ) => {
33+ bb . on ( 'file' , ( name , file , info ) => {
3434 const uploadFile = { } ;
3535
3636 file . on ( 'data' , data => {
@@ -39,31 +39,31 @@ const parse = (event) => new Promise((resolve, reject) => {
3939
4040 file . on ( 'end' , ( ) => {
4141 if ( uploadFile . content ) {
42- uploadFile . filename = filename ;
43- uploadFile . contentType = mimetype ;
44- uploadFile . encoding = encoding ;
45- uploadFile . fieldname = fieldname ;
42+ uploadFile . filename = info . filename ;
43+ uploadFile . contentType = info . mimeType ;
44+ uploadFile . encoding = info . encoding ;
45+ uploadFile . fieldname = name ;
4646 result . files . push ( uploadFile ) ;
4747 }
4848 } ) ;
4949 } ) ;
5050
51- busboy . on ( 'field' , ( fieldname , value ) => {
52- result [ fieldname ] = value ;
51+ bb . on ( 'field' , ( name , val , info ) => {
52+ result [ name ] = val ;
5353 } ) ;
5454
55- busboy . on ( 'error' , error => {
55+ bb . on ( 'error' , error => {
5656 reject ( error ) ;
5757 } ) ;
5858
59- busboy . on ( 'finish' , ( ) => {
59+ bb . on ( 'finish' , ( ) => {
6060 resolve ( result ) ;
6161 } ) ;
6262
6363 const encoding = event . encoding || ( event . isBase64Encoded ? "base64" : "binary" ) ;
6464
65- busboy . write ( event . body , encoding ) ;
66- busboy . end ( ) ;
65+ bb . write ( event . body , encoding ) ;
66+ bb . end ( ) ;
6767} ) ;
6868
6969module . exports . parse = parse ;
0 commit comments