How to return binary data from lambda function in AWS in Python?

后端 未结 4 1756
不知归路
不知归路 2020-12-14 02:18

I cannot get python lambda to return binary data. The node-template for thumbnail images works fine but I cannot get a python lambda to work. Below is the relevant lines fro

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 03:00

    As far as I can tell, this is also the case with Python 3. I'm trying to return a binary data (bytes). It's not working at all.

    I also tried to use base-64 encoding and I have had no success.

    This is with API Gateway and Proxy Integration.

    [update]

    I finally realized how to do this. I enabled binary support for type */* and then returned this:

    return({
            "isBase64Encoded": True,
            "statusCode": 200,
            "headers": {
                    "content-type": "image/jpg",
            },  
            'body':  base64.b64encode(open('image.jpg', 'rb').read()).decode('utf-8')
    })  
    

提交回复
热议问题