gpt4 book ai didi

amazon-web-services - AWS .NET Core Lambda - 图像上传损坏

转载 作者:行者123 更新时间:2023-12-02 20:26:38 32 4
gpt4 key购买 nike

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

我遇到了一个问题,下面的代码片段在我的 Windows 计算机上按预期工作(回显图像),但是当部署到 AWS Lambda 时,返回的图像被破坏。经过进一步调查,部署在 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网关??

(我正在通过 Postman 测试该问题)

最佳答案

你看过文件的内容了吗?我猜这是 html 错误结果或其他什么。

在这篇博文 ( Serverless ASP.NET Core 2.0 Applications ) 中,他们提到:

If your web application displays images, we recommend you serve those images from Amazon S3. This is more efficient for returning static content like images, Cascading Style Sheets, etc. Also, to return images from your Lambda function to the browser, you need to do extra configuration in API Gateway for binary data.

参见API Gateway for binary data了解如何配置它。

关于amazon-web-services - AWS .NET Core Lambda - 图像上传损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49705437/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com