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

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

问题描述

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

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.

在亚马逊控制台中,转至服务,然后转至 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. 图像/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天全站免登陆