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

Why is application/json listed as a binary media type in example project? #64

Closed
bolddp opened this issue Apr 27, 2017 · 5 comments · Fixed by #66
Closed

Why is application/json listed as a binary media type in example project? #64

bolddp opened this issue Apr 27, 2017 · 5 comments · Fixed by #66

Comments

@bolddp
Copy link

bolddp commented Apr 27, 2017

Hi!
I've just spent a few hours troubleshooting a strange error I got only when deploying to AWS Lambda / API Gateway, and it turns out that it is because application/json is listed in the binaryMimeTypes collection in your example project. When I removed it, the POST and PATCH calls work just fine.

What is the reason for this, in what scenario are you interested in treating JSON input data as base64?

@kahouieong
Copy link
Contributor

The intention was to treat most of the data as binary data not just base64 encoded.

@bolddp
Copy link
Author

bolddp commented Apr 27, 2017

OK, thanks for the info! I was just surprised, because the example didn't seem to work out of the box when I deployed it to AWS Lambda. The following error was thrown when I POSTed JSON data with a Content-Type of application/json. It seems that base64-encoded data is sent to the JSON parser, and I got it to work by removing application/json from binaryMimeTypes in lambda.js and the Swagger YML.

Is this the expected behavior?

2017-04-27T13:56:10.467Z 3078a373-2b50-11e7-96c6-a5828501763c SyntaxError: Unexpected token e in JSON at position 0
at Object.parse (native)
at parse (/var/task/node_modules/body-parser/lib/types/json.js:89:17)
at /var/task/node_modules/body-parser/lib/read.js:116:18
at invokeCallback (/var/task/node_modules/body-parser/node_modules/raw-body/index.js:262:16)
at done (/var/task/node_modules/body-parser/node_modules/raw-body/index.js:251:7)
at IncomingMessage.onEnd (/var/task/node_modules/body-parser/node_modules/raw-body/index.js:307:7)
at emitNone (events.js:86:13)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)

@kahouieong
Copy link
Contributor

Can you share your API setting and the request parameters?

brettstack added a commit that referenced this issue May 5, 2017
… showcase POST/PUT; move example instructions to example/README.md; update example to Node.js 6.10; added app.local.js to easily run local express
@brettstack
Copy link
Collaborator

It's listed for gzip support. However, there is a bug in the lib where it was not encoding the request correctly. PR submitted.

@brettstack
Copy link
Collaborator

Released. Please update to version 3.0.0

brettstack pushed a commit that referenced this issue Feb 9, 2018
<a name="2.1.4"></a>
## [2.1.4](v2.1.3...v2.1.4) (2018-02-09)

### Bug Fixes

* decodes base64 requests (fixes [#64](#64)); added form to index view to showcase POST/PUT;  move example instructions to example/README.md; update example to Node.js 6.10; added app.local.js to easily run local express ([2871acb](2871acb))
OneDev0411 added a commit to OneDev0411/serverless-express that referenced this issue Mar 16, 2023
<a name="2.1.4"></a>
## [2.1.4](CodeGenieApp/serverless-express@v2.1.3...v2.1.4) (2018-02-09)

### Bug Fixes

* decodes base64 requests (fixes [#64](CodeGenieApp/serverless-express#64)); added form to index view to showcase POST/PUT;  move example instructions to example/README.md; update example to Node.js 6.10; added app.local.js to easily run local express ([2871acb](CodeGenieApp/serverless-express@2871acb))
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

Successfully merging a pull request may close this issue.

3 participants