1

WE are running into an issue where a file is not getting downloaded correctly when hosted as an AWS lambda package.

.Net Core API GET Endpoint that returns

    [HttpGet()]
    [Route("ABC")]
    public async Task<IActionResult> ABC(string id)
    {  byte[] con = GetFileContent(id);
       var fileName = GetFileName(id);
       return File(con, "application/octet-stream", filename);     
    }

When we run this on local host (IISExpress) this return the file with content

But when the same is build into an AWS lambda package and deployed, it downloads the file but the file does not open and gives error as corrouted, etc

Do we need to set something in lambda to allow this download to work correctly?

Also, when we run this on POSTMan

on Local: it Returns the file in Response(Encoded- File with strange characters) On Dev: It returns the byte[]??

1 Answer 1

1

You need to go into the Amazon API Gateway console and enable binary responses. https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-payload-encodings-configure-with-console.html

What you are doing in the console is saying what Accept or content-types header values to look at on the request to determine if it is okay to return binary data. Since you can't really control the Accept header in the browser which I suspect you are calling from then setting a wildcard character in the console would probably be easiest.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the reply. So a redeploy of API gateways for the lambda resolved the issue. We just found out that changes in response headers require Gateway refresh. We had new headers added as part of this new endpoint.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.