why return base64 encoded?
See original GitHub issueHi,
If I understand correctly from #64 and #66 that listing ‘application/json’ in the binaryMimeTypes is for gzip support.
I tried to mimic the example with a simpler version. However I got the base64 encoded return. Below is the setting for lambda.js and app.js
// lambda.js
'use strict'
const awsServerlessExpress = require('aws-serverless-express')
const app = require('./app')
// NOTE: If you get ERR_CONTENT_DECODING_FAILED in your browser, this is likely
// due to a compressed response (e.g. gzip) which has not been handled correctly
// by aws-serverless-express and/or API Gateway. Add the necessary MIME types to
// binaryMimeTypes below, then redeploy (`npm run package-deploy`)
const binaryMimeTypes = [
'application/javascript',
'application/json',
'application/octet-stream',
'application/xml',
'font/eot',
'font/opentype',
'font/otf',
'image/jpeg',
'image/png',
'image/svg+xml',
'text/comma-separated-values',
'text/css',
'text/html',
'text/javascript',
'text/plain',
'text/text',
'text/xml'
]
const server = awsServerlessExpress.createServer(app, null, binaryMimeTypes)
exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context)
// app.js
'use strict'
const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
const compression = require('compression')
const awsServerlessExpressMiddleware = require('aws-serverless-express/middleware')
const app = express()
app.use(compression())
app.use(cors())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(awsServerlessExpressMiddleware.eventContext())
app.get('/testing', function (req, res) {
res.json({testing: 'testing'})
})
module.exports = app
I got return value of eyJ0ZXN0aW5nIjoidGVzdGluZyJ9 instead of {testing: ‘testing’}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:11
Top Results From Across the Web
Why does base64 encode return bytes instead of string directly?
You are correct that base64 is meant to be a textual representation of binary data. However, you are neglecting constraints on the actual ......
Read more >Base64 - MDN Web Docs Glossary: Definitions of ... - Mozilla
Encoded size increase This means that the Base64 version of a string or file will be at least 133% the size of its...
Read more >why return base64 encoded? - vendia/serverless-express
Hi, If I understand correctly from #64 and #66 that listing 'application/json' in the binaryMimeTypes is for gzip support.
Read more >Encoding and Decoding Base64 Strings in Python - Stack Abuse
Base64 encoding allows us to convert bytes containing binary or text data to ASCII characters.
Read more >base64_encode - Manual - PHP
Encodes the given string with base64. This encoding is designed to make binary data survive transport through transport layers that are not 8-bit...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For those who’s struggling the useage of binaryMimeTypes, here is my sharing. Please correct me if anything wrong.
The whole thing of adding MIME types to binaryMimeTypes is for compression. e.g. you want to gzip the application/json payload. let’s first quote from @brettstack :
“Express response -> compression/gzip middleware (if you use it) -> aws-serverless-express (encodes to base64 if content-type is specified in binaryMimeTypes in Lambda handler) -> API Gateway (decodes base64 if content-type matches a binary mime type specified on API) -> Client”
here is my little supplement for his quote.
I am working behind some gateway that is external to aws. Is there a way to turn of the base64 encoding?