title: AWS Serverless Excel download
body: <p>I am trying to download an Excel file by using below Lambda function code (ASP .Net Core 3.1) deployed in AWS. But I am getting file corrupted issue.</p>
  <p><strong>ReportController.cs:</strong></p>
  <pre><code>[HttpGet]
  public IActionResult Get()
  {
     Workbook workbook = new Workbook();
     Worksheet worksheet = workbook.Worksheets[0];
     worksheet.Zoom = 80;
     Style titleheaderStyle = worksheet.Workbook.CreateStyle();
     titleheaderStyle.Font.Name = &quot;Calibri&quot;;
     titleheaderStyle.Font.Size = 13;
     titleheaderStyle.Font.IsBold = true;
     titleheaderStyle.Font.IsItalic = true;
     titleheaderStyle.HorizontalAlignment = TextAlignmentType.Left;
     titleheaderStyle.VerticalAlignment = TextAlignmentType.Top;
     worksheet.Cells[0, 0].PutValue(&quot;Report&quot;);
     MemoryStream ms = new MemoryStream();
     workbook.Save(ms, SaveFormat.Xlsx);
     byte[] b1 = ms.ToArray();
     ms.Flush();
     Response.Clear();
     Response.ContentType = &quot;application/vnd.openxmlformats-officedocument.spreadsheetml.sheet&quot;;
     Response.Headers.Add(&quot;Content-Disposition&quot;, &quot;attachment; filename=testfile1.xlsx&quot;);
     Response.Body.WriteAsync(b1);
     return Ok();
  }
  </code></pre>
  <p><strong>LambdaEntryPoint.cs:</strong></p>
  <pre><code>protected override void Init(IWebHostBuilder builder)
  {
     RegisterResponseContentEncodingForContentType(&quot;application/vnd.openxmlformats-officedocument.spreadsheetml.sheet&quot;, ResponseContentEncoding.Base64);
     builder.UseStartup&lt;Startup&gt;();
  }
  </code></pre>
  <p>We have updated Binary Media Type as &quot;application/vnd.openxmlformats-officedocument.spreadsheetml.sheet&quot; in AWS API Gateway and set Content handling to Convert to binary (CONVERT_TO_BINARY) in GET integration response and also updated 200 status method response with &quot;application/vnd.openxmlformats-officedocument.spreadsheetml.sheet&quot; Content-Type. How to resolve the above issue?</p>
  <p><strong>Update:</strong></p>
  <pre><code>[HttpGet]
  public IActionResult Get()
  {
     Workbook workbook = new Workbook();
     Worksheet worksheet = workbook.Worksheets[0];
     worksheet.Zoom = 80;
     Style titleheaderStyle = worksheet.Workbook.CreateStyle();
     titleheaderStyle.Font.Name = &quot;Calibri&quot;;
     titleheaderStyle.Font.Size = 13;
     titleheaderStyle.Font.IsBold = true;
     titleheaderStyle.Font.IsItalic = true;
     titleheaderStyle.HorizontalAlignment = TextAlignmentType.Left;
     titleheaderStyle.VerticalAlignment = TextAlignmentType.Top;
     worksheet.Cells[0, 0].PutValue(&quot;Report&quot;);
     MemoryStream ms = new MemoryStream();
     workbook.Save(ms, SaveFormat.Xlsx);
     byte[] b1 = ms.ToArray();
     ms.Flush();
     return new FileContentResult(b1, &quot;application/vnd.openxmlformats-officedocument.spreadsheetml.sheet&quot;)
     {
        FileDownloadName = &quot;testfile1.xlsx&quot;
     };
  }
  </code></pre>