gpt4 book ai didi

asp.net - 413 请求实体太大 - Web API

转载 作者:行者123 更新时间:2023-12-04 10:44:13 25 4
gpt4 key购买 nike

我在尝试将数据从我的 Web 应用程序 (.netfx 4.6.1) 发送到我的 Web api (.net core 3.1) 时遇到了 413 问题。在下面的代码中,我发送了一个列表,其中包含图像的字节数据以及构建文件所需的附加数据。预期的输出是返回一个包含新文件的字节数组。不幸的是,在发送请求时,我收到一个错误:响应状态代码不表示成功:413(请求实体太大)。

该错误似乎仅在文件很大时才会发生,这是有道理的。我所做的研究似乎指向 IIS 中的设置,主要是 maxAllowedContentLength、maxRequestLength 和 uploadReadAheadSize。我尝试将这些值增加到更适合此过程的值,但似乎没有任何效果。我已经针对 web 应用程序和 web api 调整了它们,因为我不确定是哪个导致了问题。

问题出在哪里?在应用程序中,API,还是两者兼而有之?我是否缺少允许增加尺寸的其他设置?我发送请求的方式有问题吗?任何帮助表示赞赏。

    public static async Task<byte[]> CreatePdfFromImageFilesAsync(List<ImageFile> imageFiles)
{
var list = new List<dynamic>();
foreach (var item in imageFiles)
{
list.Add(new
{
Data = Convert.ToBase64String(item.Bytes),
PageOrder = item.PageOrder,
Rotation = item.Rotation,
Type = "PDF"
});
}

var response = _client.PostAsJsonAsync($"{FileCreatorAPI}/api/files/CreateFileFromMultiple", list).Result;
var result = response.EnsureSuccessStatusCode();
var bytes = await result.Content.ReadAsAsync<byte[]>();
return bytes;
}

最佳答案

你能检查这个属性 https://github.com/aspnet/Announcements/issues/267 ?
使用

[RequestSizeLimit(100_000_000)] 

在您的 Controller 入口点上,或更全局地以这种方式设置它:
.UseKestrel(options =>
{
options.Limits.MaxRequestBodySize = null;

编辑:来自 MS 的文章: https://dotnet.microsoft.com/download/dotnet-core

关于asp.net - 413 请求实体太大 - Web API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59789509/

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