I have a small ASP.NET Core site that I am hosting in AWS lambda. I have a simple Excel Workbook upload that is functioning correctly when hosted in an IIS Express instance (running from Visual Studio locally) but once my site is published to AWS Lambda, the binary file data is being corrupted. My code is below:
Upload.cshtml
<h3>Please pick the workbook to upload...</h3>
<div class="row">
<div class="col-md-4">
<form method="post" enctype="multipart/form-data">
<div class="form-group">
<label asp-for="WorkbookFile" class="control-label"></label>
<input asp-for="WorkbookFile" type="file" class="form-control" style="height:auto" />
<span asp-validation-for="WorkbookFile" class="text-danger"></span>
</div>
<input type="submit" asp-page-handler="Preview" value="Preview Upload" class="btn btn-default" />
</form>
</div>
</div>
Upload.cshtml.cs
[BindProperty]
[Required]
[Display(Name = "Workbook")]
public IFormFile WorkbookFile { get; set; }
public async Task<IActionResult> OnPostPreview()
{
// Perform an initial check to catch FileUpload class
// attribute violations.
if (!ModelState.IsValid)
{
return Page();
}
byte[] fileContents;
Guid workbookId;
using (var memoryStream = new MemoryStream())
{
await WorkbookFile.OpenReadStream().CopyToAsync(memoryStream);
fileContents = memoryStream.ToArray();
workbookId = SaveWorkbook(fileContents);
}
return RedirectToPage("./UploadReview", new { id = workbookId });
}
As is outlined by the AWS documentation (https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-payload-encodings.html) I have added "multipart/form-data" to my Api Gateway's "binary" types list but this does not seem to be having any effect.
API Gateway Settings Screenshot
Based on everything I can find this should allow my uploaded files to be passed as binary straight to my service, however the resulting files are 2x the size of the files when uploaded locally, so I am assuming the base64 encoding is still being applied.
All of the Request headers appear to either be multipart/form-data or application/octet-stream so I'm really at the end of my rope as I am neither a Web nor an AWS expert. Any suggestions would be greatly appreciated. Thanks!
EDIT 1. The picture (link) below shows log messages that write out the byte[] sizes I'm receiving in the ASP.NET core back-end when running local vs. running AWS.
The picture (link) below shows the Chrome dev tools showing my content-type is multipart/form-data and the length lines up with the expected size.