Search code examples
asp.net-coreaws-lambdamicroservices

Enabling binary media types breaks Option POST call (CORS) in AWS Lambda


New to AWS..

We have a .NET Core Microservice running on a serverless aws instance as lambda functions.

Our Controller looks like this

[Route("api/[controller]")]
    [ApiController]
    public class SomeController : ControllerBase
    {


        [HttpGet()]
        [Route("getsomedoc")]
        public async Task<IActionResult> GetSomeDoc()
        {
            byte[] content;

            //UI needs this to process the document
            var contentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
            contentDisposition.FileName = "File Name";

            Response.Headers[HeaderNames.ContentDisposition] = contentDisposition.ToString();

            return File(content, "application/octet-stream");
        }


        [HttpPost()]
        [Route("somepost")]
        public async Task<IActionResult> SomePost()
        {
            return null;

        }
    }

URL's

{{URL}}/getsomedoc
{{URL}}/somepost

We have enabled 'Binary Media Types' in AWS package settings to / for the getsomedoc to work otherwise it was returning the byte array back instead of the file.

But this is breaking our 'somepost' call when UI is accessing the API using Method: OPTIONS & Access-Control-Request-Method as POST

When we remove the binary media type the 'somepost' starts working.

Looking for suggestions as why this might be happening? and what can we add/remove from gateway to get this fixed.


Solution

  • Well we ended up resolving this in a strange way.

    Added two gateways for the lambda - on one of them have binary enabled - Disabled on the other one.

    For getsomedoc - Using the one where binary media types are enabled postsomedoc - Using the other one

    Wish there was a better way!!