AWS API Gateway and Lambda to return image

后端 未结 5 2187
情书的邮戳
情书的邮戳 2021-02-19 06:02

Say I have this HTML:


What I would like to do is have example.com/pic map to an AWS API Gateway end

5条回答
  •  温柔的废话
    2021-02-19 06:51

    It currently isn't possible because you cannot return binary data through the AWS API Gateway.

    For this to work, the lambda function would need to return the image data as binary blob, and some meta-information such as the image content type. Then, AWS API Gateway would need to be able to map this to the HTTP response. For example:-

    lambda returns: { contentType: 'image/png', image: "encoded binary data" }

    then API gateway would need to map contentType to the 'content-type' header of the response, and put the image data in the body of the response with the right encoding and length.

    Unfortunately, it doesn't do this right now. It only maps text encodings like application/json or application/xml as the response type (it is designed for APIs after all).

    You could very easily achieve this using ElasticBeanstalk where you have a lot more control over the http response.

提交回复
热议问题