In the local environment (Windows 7, Kestrel, AspNetCore 2.0) everything works great no errors. However, when I deploy to AWS as a LAMBDA function using API Gateway I get the bellow error.
[HttpPost]
[Route("Temp")]
public IActionResult PostTest(IFormFile file)
{
using (SpreadsheetDocument document = SpreadsheetDocument.Open(file.OpenReadStream(), false))
{
}
return Ok();
}
Unknown error responding to request: FileFormatException:
System.IO.FileFormatException: File contains corrupted data.
at System.IO.Packaging.ZipPackage..ctor(Stream s, FileMode packageFileMode, FileAccess packageFileAccess)
at System.IO.Packaging.Package.Open(Stream stream, FileMode packageMode, FileAccess packageAccess)
at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.OpenCore(Stream stream, Boolean readWriteMode)
at DocumentFormat.OpenXml.Packaging.SpreadsheetDocument.Open(Stream stream, Boolean isEditable, OpenSettings openSettings)
at api.Controllers.SKUController.Post2Async(IFormFile file) in \lambda\api\Controllers\SKUController.cs:line 72
at lambda_method(Closure , Object , Object[] )
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.MoveNext()
I am able to post the excel just fine to AWS, (And even read it using system io) but the method for SpreedsheetDocument.Open is not working. (Also checked on that I can write a text file to a temp directory that seemed to work also)
Turns out that the API Gateway was encoding it as base64, it needed to be passed in as binary and not encoded. One thing I forgot to do was also deploy it API Gateway.