Closed dyingsunlight closed 7 months ago
Hi @dyingsunlight, thanks for reporting the issue. I tried to deploy the app and browse the URL but could not see the image. As for the isBase64Encoded: False
in the debug logs, it seems this is for the input event sent to the lambda function. I think what you are looking for is the response to return True for isBase64Encoded
and looking at this code, the boolean value is a string. Can you check if setting it to a string works?
It's not working... I tried setting isBase64Encoded
to 'true'
and 'True'
, but the debug message still outputs: 'isBase64Encoded': False
.
The debug logs:
Constructed Event 1.0 to invoke Lambda. Event: {'version': '1.0', 'httpMethod': 'GET', 'body': None, 'resource': '/hello-world', 'requestContext': {'resourceId': '123456', 'apiId': '1234567890',
'resourcePath': '/hello-world', 'httpMethod': 'GET', 'requestId': '35b543fb-3f9b-4ba4-80a0-c1983c882814', 'accountId': '123456789012', 'stage': 'Prod', 'identity': {'apiKey': None, 'userArn': None, 'cognitoAuthenticationType':
None, 'caller': None, 'userAgent': 'Custom User Agent String', 'user': None, 'cognitoIdentityPoolId': None, 'cognitoAuthenticationProvider': None, 'sourceIp': '127.0.0.1', 'accountId': None}, 'extendedRequestId': None, 'path':
'/hello-world', 'protocol': 'HTTP/1.1', 'domainName': '127.0.0.1:8090', 'requestTimeEpoch': 1702792298, 'requestTime': '17/Dec/2023:05:51:38 +0000'}, 'queryStringParameters': None, 'multiValueQueryStringParameters': None,
'headers': {'Host': '127.0.0.1:8090', 'Connection': 'keep-alive', 'Cache-Control': 'max-age=0', 'Sec-Ch-Ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"', 'Sec-Ch-Ua-Mobile': '?0', 'Sec-Ch-Ua-Platform':
'"Windows"', 'Upgrade-Insecure-Requests': '1', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', 'Accept':
'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', 'Sec-Fetch-Site': 'none', 'Sec-Fetch-Mode': 'navigate', 'Sec-Fetch-User': '?1',
'Sec-Fetch-Dest': 'document', 'Accept-Encoding': 'gzip, deflate, br', 'Accept-Language': 'zh-CN,zh;q=0.9,zh-TW;q=0.8,en;q=0.7,ja;q=0.6,ru;q=0.5', 'X-Forwarded-Proto': 'http', 'X-Forwarded-Port': '8090'}, 'multiValueHeaders':
{'Host': ['127.0.0.1:8090'], 'Connection': ['keep-alive'], 'Cache-Control': ['max-age=0'], 'Sec-Ch-Ua': ['"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"'], 'Sec-Ch-Ua-Mobile': ['?0'], 'Sec-Ch-Ua-Platform':
['"Windows"'], 'Upgrade-Insecure-Requests': ['1'], 'User-Agent': ['Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'], 'Accept':
['text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7'], 'Sec-Fetch-Site': ['none'], 'Sec-Fetch-Mode': ['navigate'], 'Sec-Fetch-User': ['?1'],
'Sec-Fetch-Dest': ['document'], 'Accept-Encoding': ['gzip, deflate, br'], 'Accept-Language': ['zh-CN,zh;q=0.9,zh-TW;q=0.8,en;q=0.7,ja;q=0.6,ru;q=0.5'], 'X-Forwarded-Proto': ['http'], 'X-Forwarded-Port': ['8090']},
'pathParameters': None, 'stageVariables': None, 'path': '/hello-world', 'isBase64Encoded': False}
I believe the issue is that, according to the documentation, the 'isBase64Encoded'
value should be a boolean type, not a string type.
Marking this as a bug for the team to investigate the right behavior here.
Hi, It looks like because in the template provided the api definition does not have anything declared for the BinaryMediaTypes property SAM CLI does not try to decode the image. Changing the template to the following fixed the issue for me
{
"AWSTemplateFormatVersion": "2010-09-09",
"Transform": "AWS::Serverless-2016-10-31",
"Description": "",
"Resources": {
"HelloWorld": {
"Type": "AWS::Serverless::Function",
"Properties": {
"CodeUri": "./lambda",
"Handler": "hello-word.handler",
"Runtime": "nodejs18.x",
"Events": {
"HelloWorldEvent0": {
"Type": "Api",
"Properties": {
"Path": "/hello-world",
"Method": "get",
"RestApiId": {
"Ref": "HelloWorldApi"
}
}
}
},
"Timeout": 60,
"MemorySize": 1024
}
},
"HelloWorldApi": {
"Type": "AWS::Serverless::Api",
"Properties": {
"StageName": "prod",
"BinaryMediaTypes": ["image/png"]
}
}
}
}
Alternatively changing the event type to HttpApi
will also cause the image to be decoded. It looks like the behaviour for decoding base64 images is defined here
Thanks, it's looks working now!
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
Description:
I wan to draw image in lambda as response, but it seems broken when i using
isBase64Encoded: true
as response option.The debug output shows generated events are
isBase64Encoded: false
and output the original body as ouput.Steps to reproduce:
My project files:
lambda/hello-world.mjs
lambda/package.json
template.json
The example project can be found in https://github.com/dyingsunlight/aws-sam-bug-isBase64Encoded
Observed result:
The image is broken When edit the content as text that the text is extracly set to body before.
Response body
Expected result:
I also deploy the same code to aws lambda in production...
The response should be this
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
Add --debug flag to command you are running
DEBUG outputs