Open jbrosan opened 7 years ago
hi, sorry for my late response. I see no boundary in your payload.
take a deep look at your "body-json" string, it is a base64 encoded payload (your "post"), this is:
"LS0tLS0tV2V...WGlNLS0NCg=="
when u decode it, you can see:
------WebKitFormBoundaryqiqELBCIiRRaSXiM
Content-Disposition: form-data; name="file"; filename="johnledes98bsample.csv"
Content-Type: text/csv
LEDES1998B[]
INVOICE_DATE|INVOICE_NUMBER|CLIENT_ID|LAW_FIRM_MATTER_ID|INVOICE_TOTAL|BILLING_START_DATE|BILLING_END_DATE|INVOICE_DESCRIPTION|LINE_ITEM_NUMBER|EXP/FEE/INV_ADJ_TYPE|LINE_ITEM_NUMBER_OF_UNITS|LINE_ITEM_ADJUSTMENT_AMOUNT|LINE_ITEM_TOTAL|LINE_ITEM_DATE|LINE_ITEM_TASK_CODE|LINE_ITEM_EXPENSE_CODE|LINE_ITEM_ACTIVITY_CODE|TIMEKEEPER_ID|LINE_ITEM_DESCRIPTION|LAW_FIRM_ID|LINE_ITEM_UNIT_COST|TIMEKEEPER_NAME|TIMEKEEPER_CLASSIFICATION|CLIENT_MATTER_ID
19990225|96542|00711|0528|1684.45|19990101|19990131|For services rendered|1|F|2.00|-70|630|19990115|L510||A102|22547|Research Attorney’s fees, Set off claim|24-6437381|350|Arnsley, Robert|PARTNR|423-987[]
19990225|96542|00711|0528|1684.45|19990101|19990131|For services rendered|2|F|2.00|0|700|19990115|L510||A102|22547|Research attorney's fees, Trial pleading|24-6437381|350|Arnsley, Robert|PARTNR|423-987[]
19990225|96542|00711|0528|1684.45|19990101|19990131|For services rendered|3|F|0.200|0|40|19990116|L510||A107|45875|Telephone conference with John Doe|24-6437381|200|Beaster, John|ASSOC|423-987[]
19990225|96542|00711|0528|1684.45|19990101|19990131|For services rendered|4|E|1|0|24.95|19990117||E111|||Meals|24-6437381|24.95|||423-987[]
19990225|96542|00711|0528|1684.45|19990101|19990131|For services rendered|5|E|1|0|289.5|19990117||E110|||Out-of_town travel|24-6437381|289.5|||423-987[]
19990225|96542|00711|1326|1250|19990101|19990131|Monthly Retainer|6|IF|1|1250.|1250|19990131|||||Monthly Retainer Fee|24-6437381||||425-936[]
20160930|96554|00814|0628|684.50|20160901|20160930|For services rendered|1|F|3.50|-30|656|20160115|L510||A102|22547|Research Attorney’s fees, Set off claim|24-6437381|350|Arnsley, Robert|PARTNR|423-987[]
20160930|96554|00814|0628|684.50|20160901|20160930|For services rendered|2|F|4.00|0|701|20161115|L510||A102|22547|Research attorney's fees, Trial pleading|24-6437381|350|Arnsley, Robert|PARTNR|423-987[]
20160930|96554|00814|0628|684.50|20160901|20160930|For services rendered|3|F|0.300|0|41|20160317|L510||A107|45875|Telephone conference with John Doe|24-6437381|200|Beaster, John|ASSOC|423-987[]
20171130|86542|00322|0628|684.50|20171101|20171130|For services rendered|4|E|1|0|34.95|20170117||E111|||Meals|24-6437381|24.95|||423-987[]
20171130|86542|00322|0628|684.50|20171101|20171130|For services rendered|5|E|1|0|301.5|20170321||E110|||Out-of_town travel|24-6437381|289.5|||423-987[]
20171130|86542|00322|1426|1250|20171101|20171130|Monthly Retainer|6|IF|1|1250.|1250|20171031|||||Monthly Retainer Fee|24-6437381||||425-936[]
------WebKitFormBoundaryqiqELBCIiRRaSXiM--
As you can see in your payload, the boundary is there:
----WebKitFormBoundaryqiqELBCIiRRaSXiM
The problem i see is: The boundary doesnt come in the original parameters, it should.
Todo:
(worst) If you cant find a way to have this boundary in the events data, then hack it..read the base64 encoded payload and extract the string "----WebKitFormBoundaryqiqELBCIiRRaSXiM" (it will change on every post, so find a way to retrieve it). Then, use this boundary instead of a call to getBoundary().
(possible cause) Maybe your html code (the form) does not explicitly set the "multipart/form-data" attribute. So, your apigateway expects a multipart/form-data payload, and because the form doesnt provide it then the boundary is not set (the browser submitting your form is the responsible to provide it, not apigateway.
(best solution) the getBoundary method is designed to read the boundary from your incoming data from "event.params.header", this header is created by the Apigateway.
var boundary = multipart.getBoundary(event.params.header['content-type']);
In your apigateway, in the specific method (POST or GET), look at the "Integration Request", then "Body Mapping Templates", and ensure you are providing the right values, this values are created on-the-fly by apigateway using a code-template.
Next code fragement is a copy of my own template (created automatically by apigeteway), this templated is executed by apigateway and it copies values from the apigateway to your service (in json format), so maybe you miss something in this part (look at the "params" part, apigateway will build it, and, it should provide it: events.params.header...).
(you can copy and paste this code into your "Body Mapping Template")
#set($allParams = $input.params())
{
"body-json" : $input.json('$'),
"params" : {
#foreach($type in $allParams.keySet())
#set($params = $allParams.get($type))
"$type" : {
#foreach($paramName in $params.keySet())
"$paramName" : "$util.escapeJavaScript($params.get($paramName))"
#if($foreach.hasNext),#end
#end
}
#if($foreach.hasNext),#end
#end
},
"stage-variables" : {
#foreach($key in $stageVariables.keySet())
"$key" : "$util.escapeJavaScript($stageVariables.get($key))"
#if($foreach.hasNext),#end
#end
},
"context" : {
"account-id" : "$context.identity.accountId",
"api-id" : "$context.apiId",
"api-key" : "$context.identity.apiKey",
"authorizer-principal-id" : "$context.authorizer.principalId",
"caller" : "$context.identity.caller",
"cognito-authentication-provider" : "$context.identity.cognitoAuthenticationProvider",
"cognito-authentication-type" : "$context.identity.cognitoAuthenticationType",
"cognito-identity-id" : "$context.identity.cognitoIdentityId",
"cognito-identity-pool-id" : "$context.identity.cognitoIdentityPoolId",
"http-method" : "$context.httpMethod",
"stage" : "$context.stage",
"source-ip" : "$context.identity.sourceIp",
"user" : "$context.identity.user",
"user-agent" : "$context.identity.userAgent",
"user-arn" : "$context.identity.userArn",
"request-id" : "$context.requestId",
"resource-id" : "$context.resourceId",
"resource-path" : "$context.resourcePath"
}
}
Hi christiansalazar,
Thank you for your response. You were absolutely correct. The boundary was not being set correctly. A header was being set and was overwriting the boundary information. Once I pulled that out, it all worked great!
Thanks again for your help and your response. I really appreciate it!
Cheers! John
:)
Hi,
I am currently experiencing an issue with uploading a file using multipart/form-data to AWS. I've setup the API Gateway as you have it in your video and added my lambda.
It seems that the getBoundary method is not returning a boundary and when I attempt to parse into parts that its just not working. The parts array is empty.
Any ideas or suggestions on what could be happening and how to resolve it would be most appreciated.
Thanks , John
LAMBDA
The event