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

后端 未结 4 1754
不知归路
不知归路 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条回答
  •  情歌与酒
    2020-12-14 02:40

    I faced the same problem about 6 months ago. Looks like although there is now binary support (and examples in JS) in API Gateway, Python 2.7 Lambda still does not support valid binary response, not sure about Python 3.6.

    Base64 encoded response is having problems because of JSON wrapping. I wrote a custom JS on client side taking the base-64 image out of this JSON manually, but this was also a poor solution.

    Upload the result to S3 (behind the CloudFront) and return 301 to CloudFront seems to be a good workaround. Works best for me.

提交回复
热议问题