您可以使用base64编码将图像转换为字符串形式,并将其作为Lambda函数的输出返回。然后,在客户端接收到该字符串后,使用相应的解码器将其转换回图像。以下是示例代码:
Lambda函数:
import base64
def lambda_handler(event, context): with open("image.png", "rb") as image_file: encoded_string = base64.b64encode(image_file.read()) return { "statusCode": 200, "headers": {"Content-Type": "application/json"}, "body": encoded_string.decode('utf-8') }
客户端:
import base64 import requests
response = requests.get("<