联系我们

Serving images through AWS Api Gateway from Serverless Lambda_proxy function

Sitecore MVP & Principal Developer at Valtech
Valtech, UK

四月 18, 2018

In another post I mentioned the neat features now available in AWS: Serverless templates. As part of an experiment I thought it would be interesting to see how you could put a light security layer over S3 so that media requests stream from S3 if a user logs in.

The WebApi template  already ships with an S3 proxy controller. Tweaking this slightly allowed me to stream or download the image:Screen Shot 2019-07-03 at 10.50.05 AM.png

The issue I ran into was accessing images via the endpoint you then get in API Gateway – images were getting encoded so wouldn’t render in the browser.

The solution:

  • In the settings for your api gateway, add the Binary Media Type: */*
  • On the {proxy+} method ‘Method Response’ add a 200 response header and add a header Content-Type. Finally publish your api

The second step here may not be necessary but I found the */* didn’t kick in until I made the change.

Original article was posted on Boro2g Blog: Serving images through AWS API Gateway

联系我们

我們很樂意聽到您的聲音!請填寫表格,辦公室最近的人員將與您聯繫。
如果您需要其他格式和/或溝通支援來提供回饋,請聯絡Sheree Atcheson

让我们重新创造未来