Skip to content

Decoding base64 encoded request body#3

Closed
AlexLast wants to merge 4 commits into
sivel:masterfrom
AlexLast:master
Closed

Decoding base64 encoded request body#3
AlexLast wants to merge 4 commits into
sivel:masterfrom
AlexLast:master

Conversation

@AlexLast
Copy link
Copy Markdown

  • When using binary media types in API gateway, request bodies are base64 encoded. This allows the body to be decoded.

Comment thread flask_lambda.py Outdated

class FlaskLambda(Flask):
def __call__(self, event, context):
if 'isBase64Encoded' in event and event['isBase64Encoded']:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don’t check if a key is in the duct and then fetch it. Use .get instead.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason I thought .get was deprecated, will update..

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Comment thread flask_lambda.py Outdated
class FlaskLambda(Flask):
def __call__(self, event, context):
if event.get('isBase64Encoded', False):
event['body'] = base64.b64decode(event['body'])
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines should prob ably go after the if 'httpMethod'... block, so that we are only doing this when in lambda, and not doing it before we make that determination.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sivel Fair comment, I've moved this under the httpMethod condition block so it will only be caught if we're in Lambda.

@AlexLast AlexLast closed this Aug 13, 2021
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 this pull request may close these issues.

2 participants