Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'split' of undefined at obj (/var/task/node_modules/parse-multipart/multipart.js:28:15) #4

Open
simjaemun2 opened this issue Jul 5, 2017 · 13 comments

Comments

@simjaemun2
Copy link

simjaemun2 commented Jul 5, 2017

Hi.

As you requested, I re-write my issue on this board.

I use your library on AWS lambda to parse multi-part, but there is an error below.

2017-07-05T12:46:46.067Z 01141173-6180-11e7-90dc-d3dd47bfb325 TypeError: Cannot read property 'split' of undefined
at obj (/var/task/node_modules/parse-multipart/multipart.js:28:15)
at process (/var/task/node_modules/parse-multipart/multipart.js:37:14)
at Object.exports.Parse (/var/task/node_modules/parse-multipart/multipart.js:87:19)
at exports.handler (/var/task/index.js:13:27)

I just copy-and paste code with your You-tube video for AWS lambda.
https://www.youtube.com/watch?v=BrYJlR0yRnw&t=183s

My aws lambda console log of bodyBuffer is below
(var bodyBuffer = new Buffer(event['body-json'].toString(), 'base64');)

2017-07-05T12:46:46.065Z 01141173-6180-11e7-90dc-d3dd47bfb325 ------WebKitFormBoundaryueWlWZHlQiRyCHAU
Content-Disposition: form-data; name="testMessage"

test message 12356
------WebKitFormBoundaryueWlWZHlQiRyCHAU
Content-Disposition: form-data; name="testFile"; filename="123.tgz"
Content-Type: application/x-compressed

� ��\Y

I have not docker image, because I just use AWS Lambda!!

If you have any question, I'll help you.
Thank you.!!

@christiansalazar
Copy link
Contributor

ok, thanku for your time. Will review your case in short, please keep a little bit patience because im overloaded in this moment.

@christiansalazar
Copy link
Contributor

ok. i see you use the video https://www.youtube.com/watch?v=BrYJlR0yRnw&t=183s.

please ensure your apigateway is working fine and it is passing the event object to your lambda function. in order to do such debugging task please add this line to your lambda function:

// put this line in the very beggining of your lambda function, in order to see what is received from your apigateway, and copy paste the result in this comments section using the source code formatter.
console.log("event=",JSON.stringify(event));

@simjaemun2
Copy link
Author

I attached the console log as you requested!!

2017-07-05T23:17:58.956Z 2f01d974-61d8-11e7-9b9a-87f6b4f45038 event=
{
"body-json": "LS0tLS0tV2ViS2l0Rm9ybUJvdW5kYXJ5b0NhUEp1d0NHWkI1RzVKcQ0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJ0ZXN0TWVzc2FnZSINCg0KdGVzdCBtZXNzYWdlIDEyMzU2DQotLS0tLS1XZWJLaXRGb3JtQm91bmRhcnlvQ2FQSnV3Q0daQjVHNUpxDQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7IG5hbWU9InRlc3RGaWxlIjsgZmlsZW5hbWU9IjEyMy50Z3oiDQpDb250ZW50LVR5cGU6IGFwcGxpY2F0aW9uL3gtY29tcHJlc3NlZA0KDQofiwgIgd9cWQALMTIzLnRhcgDtzjEOwCAMQ1FOVBG7CRdj6PEbGNkjFr/lS55s4DO/2Sr1NNx309nEZjREvB0Da/dgtvSVLAbeviAiIhf8UCKb4gAIAAANCi0tLS0tLVdlYktpdEZvcm1Cb3VuZGFyeW9DYVBKdXdDR1pCNUc1SnEtLQ0K",
"params": {
"path": {},
"querystring": {},
"header": {
"Accept": "/",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "ko-KR,ko;q=0.8,en-US;q=0.6,en;q=0.4",
"CloudFront-Forwarded-Proto": "https",
"CloudFront-Is-Desktop-Viewer": "true",
"CloudFront-Is-Mobile-Viewer": "false",
"CloudFront-Is-SmartTV-Viewer": "false",
"CloudFront-Is-Tablet-Viewer": "false",
"CloudFront-Viewer-Country": "JP",
"content-type": "multipart/form-data; boundary=----WebKitFormBoundaryoCaPJuwCGZB5G5Jq",
"Host": "tq8v5d6519.execute-api.eu-west-1.amazonaws.com",
"origin": "chrome-extension://aejoelaoggembcahagimdiliamlcdmfm",
"User-Agent": "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36",
"Via": "2.0 8b7e90334ec70d80a1c64b5d3e7b02da.cloudfront.net (CloudFront)",
"X-Amz-Cf-Id": "6XevRcSYlSgJfV9RxV1gZtrfe-3sRIKtQGpjgSaLc5U8RgMPDnD5PQ==",
"X-Amzn-Trace-Id": "Root=1-595d73a6-40583e961eb5d60550175faa",
"X-Forwarded-For": "52.198.139.63, 54.182.232.91",
"X-Forwarded-Port": "443",
"X-Forwarded-Proto": "https"
}
},
"stage-variables": {},
"context": {
"account-id": "",
"api-id": "tq8v5d6519",
"api-key": "",
"authorizer-principal-id": "",
"caller": "",
"cognito-authentication-provider": "",
"cognito-authentication-type": "",
"cognito-identity-id": "",
"cognito-identity-pool-id": "",
"http-method": "POST",
"stage": "test_ht_lambda",
"source-ip": "52.198.139.63",
"user": "",
"user-agent": "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36",
"user-arn": "",
"request-id": "2eff68a7-61d8-11e7-8d4a-cdd7651836df",
"resource-id": "tl9osjrcz8",
"resource-path": "/"
}
}

@christiansalazar
Copy link
Contributor

christiansalazar commented Jul 5, 2017

ok. have a little bit of patience, im stucked in other stuff, and will put my eye in your case very soon (tomorrow).

thanku :)

@christiansalazar
Copy link
Contributor

@simjaemun2 Hello! right now im on it. I can reproduce your problem in my side, the solution is on the way :)

christiansalazar pushed a commit that referenced this issue Jul 7, 2017
@christiansalazar
Copy link
Contributor

dear @simjaemun2
please clone this branch into your repository and let me know if the problem was solved, use this command line:

cd /your/project/node_modules/
rm -rf parse-multipart;
git clone -b 4 https://github.com/freesoftwarefactory/parse-multipart 

Later, i will publish a new release and you can then proceed as you normally do via "npm install". By now, please proceed manually.

@christiansalazar christiansalazar changed the title I've got Error!! TypeError: Cannot read property 'split' of undefined at obj (/var/task/node_modules/parse-multipart/multipart.js:28:15) Jul 7, 2017
@simjaemun2
Copy link
Author

Okay, but I'm on vacation now. I'll check your comment after next week. 👍

@simjaemun2
Copy link
Author

Hi.
I executed my nodejs handler with your new branch, and it worked well.

But, Your code has some bugs.

I sent to my nodejs handler on AWS lambda with multipart/form-data that I attached before.

When I print console log of data part in case of NOT_A_FILE,
log string data didn't show data correctly, but show boundary data.

` var parts = multipart.Parse(bodyBuffer, boundary);

console.log(bodyBuffer);
console.log(parts);
console.log(typeof parts);

for(var part in parts){
    console.log("=========== part ===========");
    console.log(typeof part);
    console.log(part)
    console.log("filename : " + part.filename);
    console.log("type : " + part.type);
    
    console.log("data : " + part.data);

    console.log(typeof part.data);
}`

result is like below code.

------WebKitFormBoundaryQOr5Z2KzAgHBK

The correct data is here.

12356

I used Restlet Client that is Chrome Extension to send RESTful API with multipart/form-data.

@rcfrias
Copy link

rcfrias commented Aug 17, 2017

parts with branch 4 are parsed this way:

parts: 
{ filename: 'NOT_A_FILE',
  type: 'text/plain',
  data: <Buffer 2d 2d 2d 2d 2d 2d 57 65 62 4b 69 74 46 6f 72 6d 42 6f 75 6e 64 61 72 79 71 30 6b 42 6d 67 36 65 44 4b 31 39 72> }
{ filename: 'NOT_A_FILE',
  type: 'text/plain',
  data: <Buffer 2d 2d 2d 2d 2d 2d 57 65 62 4b 69 74 46 6f 72 6d 42 6f 75 6e 64 61 72 79 71 30 6b 42 6d 67 36 65 44 4b 31 39 72> }
{ filename: 'NOT_A_FILE',
  type: 'text/plain',
  data: <Buffer 2d 2d 2d 2d 2d 2d 57 65 62 4b 69 74 46 6f 72 6d 42 6f 75 6e 64 61 72 79 71 30 6b 42 6d 67 36 65 44 4b 31 39 72> }
{ filename: 'productImage.jpg',
  type: 'image/jpeg',
  data: <Buffer ef bf bd ef bf bd ef bf bd ef bf bd 00 10 4a 46 49 46 00 01 01 00 00 01 00 01 00 00 ef bf bd ef bf bd 00 43 00 03 02 02 02 02 02 03 02 02 02 03 03 03 ... > }

The file is parsed correctly, but the fields are not. Data Buffer in the fields parts is as @simjaemun2 mentioned the "Boundary" i.e. ------WebKitFormBoundaryQOr5Z2KzAgHBK

Field's data is captured in a different step.
#7

@richpicking
Copy link

Hi, I have a similar error.. was working fine and i can't figure out what changed..
Event logged below - many thanks for any ideas :-)


20:37:21
2018-04-13T20:37:21.133Z 76fcddd0-3f5a-11e8-9008-bd60f9169f15 { resource: '/docUpload', path: '/docUpload', httpMethod: 'POST', headers: { Accept: 'application/json', 'Accept-Encoding': 'gzip, deflate, br', 'Accept-Language': 'en-US,en;q=0.9', 'CloudFront-Forwarded-Proto': 'https', 'CloudFront-Is-Desktop-Viewer': 'true', 'CloudFront-Is-Mobile-Viewer': 'false',
2018-04-13T20:37:21.133Z 76fcddd0-3f5a-11e8-9008-bd60f9169f15 { resource: '/docUpload',
path: '/docUpload',
httpMethod: 'POST',
headers:
{ Accept: 'application/json',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.9',
'CloudFront-Forwarded-Proto': 'https',
'CloudFront-Is-Desktop-Viewer': 'true',
'CloudFront-Is-Mobile-Viewer': 'false',
'CloudFront-Is-SmartTV-Viewer': 'false',
'CloudFront-Is-Tablet-Viewer': 'false',
'CloudFront-Viewer-Country': 'GB',
'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryPaaDVyqsidpTIjfR',
Host: '588m3skmr4.execute-api.us-east-1.amazonaws.com',
origin: 'https://run.plnkr.co',
Referer: 'https://run.plnkr.co/JpqY5ZH9ZxskBBII/',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
Via: '2.0 484b0b1907e1f2b72b1dcf81d0a56212.cloudfront.net (CloudFront)',
'X-Amz-Cf-Id': '21anbMkRQOMXcbHvhnCKy-vL-3fZxhOFguqGn8nuzjo1joXGd3BW9w==',
'X-Amzn-Trace-Id': 'Root=1-5ad11501-67fe290011d4fb00c1517700',
'X-Forwarded-For': '81.129.206.126, 54.240.147.19',
'X-Forwarded-Port': '443',
'X-Forwarded-Proto': 'https' },
queryStringParameters: null,
pathParameters: null,
stageVariables: null,
requestContext:
{ resourceId: '6iv0us',
resourcePath: '/docUpload',
httpMethod: 'POST',
extendedRequestId: 'FTA4KEqSoAMFa5A=',
requestTime: '13/Apr/2018:20:37:21 +0000',
path: '/test/docUpload',
accountId: '018062810484',
protocol: 'HTTP/1.1',
stage: 'test',
requestTimeEpoch: 1523651841070,
requestId: '76fd0517-3f5a-11e8-aa2c-55b791057aae',
identity:
{ cognitoIdentityPoolId: null,
accountId: null,
cognitoIdentityId: null,
caller: null,
sourceIp: '81.129.206.126',
accessKey: null,
cognitoAuthenticationType: null,
cognitoAuthenticationProvider: null,
userArn: null,
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
user: null },
apiId: '588m3skmr4' },
body: 'LS0tLS0tV2ViS2l0Rm9ybUJvdW5kYXJ5UGFhRFZ5cXNpZHBUSWpmUg0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJ0b2tlbiINCg0KMDNBSkl6WFo1eUw5WFFDbmlOUGt4SGtLSnpvaDgyYnB0VVRjSTFuOW9uN1R6Q0I1TG4zTzZ2MWZWbWlmMHV2SjVlWTdjSV9QYVBpaDJyYnZBckp0V2IwRE9YRWRBcV83azcwT3pYSmdCSXhrODRlcEw4U29OYkJydzRHVThoUXBOaFpGWGF1eWE0X1dhLWFQRWN1TTNTZWlDLWgxR1hRNUxMSmVxQzBQY01WNVpTVEl0TzZlV2hsY2pvQ2E0T2JtVmRVNHhJREpzOE1HQ01LcHlhVE5hbnpuT0taQ1E4dGhpY1U2WmZqRUExbW84cFBfU3lDNzJrODBqUGlIeHFvaHZWN1lFaFYxUHBaMnVCaW5GeEpZMDFtdXZHT0JTMFlxVUczRUVaenpudU9jV0NUNkdOOXZBTEFySkdxa2VQN2VkcmNlQ3BjY251TUVoRVg0UHFneWI0cmI5Z1lob3NzRC1LaVhVTGh1YkVfd2xGSE1odlRoMTNuenhKQnpraV94LVRtR1IzR3Z0VGNwdXRxMkI4NEo1ZXBqRmplZkVMMkRfcmsxRlktQTY4bGtIaHF0QTgzcEhDQ1k3R1NGaFdIcll1TmFVVnhlenMtOWVLdzZ3T3hFM3RMbUtHWHoxTW8tRzl4WG1aYzZyVTJ2TWxVMWFjYTF4LW1rSjlvZ3ZMSkpxNzhZTGh5ZWRxemhyZWh5VFl5YUJxMmxUMXpCNXhaUzIzVHk5cTRaSVNTMGNZWFVnV0xuOEpIeVkNCi0tLS0tLVdlYktpdEZvcm1Cb3VuZGFyeVBhYURWeXFzaWRwVElqZlINCkNvbnRlbnQtRGlzcG9zaXRpb246IGZvcm0tZGF0YTsgbmFtZT0ibm9vZmZpbGVzIg0KDQpCbGFoIGRpIGJsYWggZGkgYmxhaCBkbyB5b3UgbGlrZSB0aGlzIGJldHRlciA/DQotLS0tLS1XZWJLaXRGb3JtQm91bmRhcnlQYWFEVnlxc2lkcFRJamZSDQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7IG5hbWU9ImRvY3VtZW50RmlsZVswXSI7IGZpbGVuYW1lPSJ0ZXN0eC50eHQiDQpDb250ZW50LVR5cGU6IHRleHQvcGxhaW4NCg0KeHh4eHh4eHh4eHh4eHh4eHh4eHh4eHgKeHh4eHh4eHh4eHgNCi0tLS0tLVdlYktpdEZvcm1Cb3VuZGFyeVBhYURWeXFzaWRwVElqZlItLQ0K',
isBase64Encoded: true }

20:37:21
2018-04-13T20:37:21.160Z 76fcddd0-3f5a-11e8-9008-bd60f9169f15 TypeError: Cannot read property '0' of null at body.split.filter.map (/var/task/node_modules/aws-lambda-multipart-parser/index.js:17:67) at Array.map (native) at Object.module.exports.parse (/var/task/node_modules/aws-lambda-multipart-parser/index.js:12:10) at exports.handler (/var/task/index.js:35:29)
2018-04-13T20:37:21.160Z 76fcddd0-3f5a-11e8-9008-bd60f9169f15 TypeError: Cannot read property '0' of null
at body.split.filter.map (/var/task/node_modules/aws-lambda-multipart-parser/index.js:17:67)
at Array.map (native)
at Object.module.exports.parse (/var/task/node_modules/aws-lambda-multipart-parser/index.js:12:10)
at exports.handler (/var/task/index.js:35:29)

20:37:21
END RequestId: 76fcddd0-3f5a-11e8-9008-bd60f9169f15

@fhackenb
Copy link

fhackenb commented Oct 8, 2018

The pull request that @rcfrias made solved this issue for me #7

@hyuntaek-twigfarm
Copy link

It solved the problem. can you please release the new version?

@WafiqSalie
Copy link

I'm getting the same error. Was the fix released to master?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants