1
1
'use strict' ;
2
2
3
- const Busboy = require ( 'busboy' ) ;
3
+ const busboy = require ( 'busboy' ) ;
4
4
5
5
/*
6
6
* This module will parse the multipart-form containing files and fields from the lambda event object.
@@ -21,7 +21,7 @@ const Busboy = require('busboy');
21
21
}
22
22
*/
23
23
const parse = ( event ) => new Promise ( ( resolve , reject ) => {
24
- const busboy = new Busboy ( {
24
+ const bb = busboy ( {
25
25
headers : {
26
26
'content-type' : event . headers [ 'content-type' ] || event . headers [ 'Content-Type' ]
27
27
}
@@ -30,7 +30,7 @@ const parse = (event) => new Promise((resolve, reject) => {
30
30
files : [ ]
31
31
} ;
32
32
33
- busboy . on ( 'file' , ( fieldname , file , filename , encoding , mimetype ) => {
33
+ bb . on ( 'file' , ( name , file , info ) => {
34
34
const uploadFile = { } ;
35
35
36
36
file . on ( 'data' , data => {
@@ -39,31 +39,31 @@ const parse = (event) => new Promise((resolve, reject) => {
39
39
40
40
file . on ( 'end' , ( ) => {
41
41
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 ;
46
46
result . files . push ( uploadFile ) ;
47
47
}
48
48
} ) ;
49
49
} ) ;
50
50
51
- busboy . on ( 'field' , ( fieldname , value ) => {
52
- result [ fieldname ] = value ;
51
+ bb . on ( 'field' , ( name , val , info ) => {
52
+ result [ name ] = val ;
53
53
} ) ;
54
54
55
- busboy . on ( 'error' , error => {
55
+ bb . on ( 'error' , error => {
56
56
reject ( error ) ;
57
57
} ) ;
58
58
59
- busboy . on ( 'finish' , ( ) => {
59
+ bb . on ( 'finish' , ( ) => {
60
60
resolve ( result ) ;
61
61
} ) ;
62
62
63
63
const encoding = event . encoding || ( event . isBase64Encoded ? "base64" : "binary" ) ;
64
64
65
- busboy . write ( event . body , encoding ) ;
66
- busboy . end ( ) ;
65
+ bb . write ( event . body , encoding ) ;
66
+ bb . end ( ) ;
67
67
} ) ;
68
68
69
69
module . exports . parse = parse ;
0 commit comments