Downloaded files are corrupted when publishing on AWS lambda

0

Hello,
I have .Net core 2.1 project which I am publishing on AWS Lambda, some endpoints I have will get a file from S3 and download it to me.
The thing is when I test locally, the same audio/image file is returned fully to me and I can preview it but when I publish to Lambda I get corrupted files, that I can't preview.

Anything I should configure to fix this?
A code sample:
[HttpGet("person/image")]
public ActionResult<IFormFile> GetPortrait([FromRoute] string imageId)
{
Stream image=GetFromS3(imageId);
return File(image, "image/jpeg"); // returns a FileStreamResult
}

yahya92
asked 5 years ago986 views
1 Answer
0

Are you returning the results through API Gateway? If so, API Gateway tries to return text or base64 encoded data. Do a web search for 'how to return S3 data from API Gateway' - there are some special API Gateway settings that have to be implemented.

I wanted to return a 1x1 pixel image but instead, I returned a redirect to a public bucket with the file!

MPT.

answered 5 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions