AWS .NET Core Lambda-图像上传中断 [英] AWS .NET Core Lambda - Image Upload Broken

查看:90
本文介绍了AWS .NET Core Lambda-图像上传中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用.NET Core通过AWS Lambda构建Web API.

I'm in the process of building a Web API with AWS Lambda using .NET Core.

我遇到了一个问题,下面的代码段可以在Windows机器上正常工作(回显图像),但是当部署到AWS Lambda时,返回的图像已损坏.经过进一步调查后,在AWS上部署时,回显的文件大小几乎是发送文件的大小的两倍?

I have run into a problem, where the code piece below work as expected on my Windows machine (Echo the image back), but when deployed to AWS Lambda, the returned image is broken. After further investigation, the echoed back file's size is nearly double the size of the sending file when deployed on AWS?

[HttpPost]
public async Task<IActionResult> Post(IFormFile file)
{
    using (var tmpStream = new MemoryStream())
    {
        await file.CopyToAsync(tmpStream);
        var fileExtension = Path.GetExtension(file.FileName);
        return File(tmpStream.ToArray(), file.ContentType);
    }
}

我是否缺少某些配置或忽略了某些内容? AWS网关??

Am I missing some configuration or overlooking something? AWS Gateway??

(我正在通过邮递员测试问题)

(I'm testing the issue via Postman)

推荐答案

您看过文件的内容吗?我猜这是html错误的结果.

Did you look at the contents of the file? My guess it is the html error result or something.

在此博客文章中( Serverless他们提到的ASP.NET Core 2.0应用程序):

如果您的Web应用程序显示图像,我们建议您从Amazon S3提供这些图像.这对于返回静态内容(例如图像,级联样式表等)更有效.此外,要将Lambda函数中的图像返回到浏览器,您需要在请参见用于二进制数据的API网关,用于配置它.

这篇关于AWS .NET Core Lambda-图像上传中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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