从浏览器将图像文件上传到AWS Lambda .Net Core应用程序会导致文件不可用-如何解决? [英] Uploading image file to AWS Lambda .Net Core application from browser results in unusable file - how to fix?

查看:139
本文介绍了从浏览器将图像文件上传到AWS Lambda .Net Core应用程序会导致文件不可用-如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从浏览器中将jpg图像作为表单的一部分上传到驻留在AWS Lambda上的.Net Core Web api。它已上传,但在尝试使用ImageSharp处理它时导致错误。我也注意到上传版本的文件大小几乎是原始文件大小的两倍。请注意,在从Visual Studio 2019 Preview运行的Windows环境中本地上载时没有问题。

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.

更多信息:图像作为IForm中的IFormFile进入我的.NET控制器。

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

推荐答案

AWS在访问AWS Lambda之前会对文件进行了某些处理。该修复程序易于实现。

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

在Amazon控制台中,转到服务,然后转到 API网关页面。 (现在请参见下面的图片!)选择您的API,然后在您的API下转到设置。添加以下二进制类型:

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

并单击保存。

现在单击资源,然后单击操作并选择部署API。

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

现在选择一个阶段。 (我在随后出现的框中将阶段设置为Prod。)然后单击Deploy按钮。

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

此时您应该准备好出发。如果不是,则可能是缓存问题尚未解决。如果是这种情况,也许可以重做上面的部署api过程。也许这会浪费时间刷新缓存或推动缓存刷新,但是很快它应该以一种或另一种方式工作。

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.

这篇关于从浏览器将图像文件上传到AWS Lambda .Net Core应用程序会导致文件不可用-如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆