Uploading image file to AWS Lambda .Net Core application from browser results in unusable file - how to fix?

穿精又带淫゛_ 提交于 2020-03-06 10:15:10

问题


I was uploading a jpg image from my browser, as a part of a form, to my .Net Core web api which resides on AWS Lambda. It uploaded but resulted in errors when I tried to process it using ImageSharp. Also I noticed that the file size of the uploaded version was almost double the size of the original. Note that there was no a problem when uploaded locally in my Windows environment running from Visual Studio 2019 Preview. It is the version that was published to AWS Lambda from Visual Studio that was having issues.

Further info: Image arrived into my .NET Controller as an IFormFile within an IForm.


回答1:


AWS does something to the file before it gets to AWS Lambda. The fix is simple to implement.

In the Amazon Console, Go to Services, then to the API Gateway page. (Now refer to image below!) Select your API and under your API go to settings. Add these binary types:

  1. image/jpeg
  2. multipart/form-data

And click Save.

Now click on Resources, then click on Actions and select Deploy API.

Now select a stage. (I set the stage to Prod in the box that comes up.) Then click on the Deploy button.

At this point you should be ready to go. If not, maybe it is a cache issue that has not caught up. If that is the case, perhaps redo the deploy api procedure above. Perhaps that kills time in which the cache refreshes or pushes a cache refresh, but soon it should work one way or another.



来源:https://stackoverflow.com/questions/56695746/uploading-image-file-to-aws-lambda-net-core-application-from-browser-results-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!