asp.net-core - 如何在 asp.net core(3.1) 应用程序中设置 maxJsonLength
问题描述
如果文件大小在 100mb 以内,则 asp.net 核心 webAPI 控制器返回文件的 base64 字符串,应用程序将下载该文件。但是当文件大小超过接近 100mb AJAX 请求时会出现 500 错误“System.ArgumentException:长度为 216539224 的 JSON 值太大且不受支持。”我在 ASP.NET 核心项目中添加了 web.config 文件并设置 maxJsonLength = web.config 文件中的 2147483644 但问题仍未解决。需要帮助
<configuration>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483644"/>
</webServices>
</scripting>
</system.web.extensions>
</configuration>
[HttpPost]
public async Task<ActionResult> CreatePDF(string json) {
try
{
string userFilePath = @"D:\file.pdf";
string base64File = Convert.ToBase64String(System.IO.File.ReadAllBytes(userFilePath));
ErrorLog.LogInformation("Task Compeleted " + userFilePath);
return Json(new { ReturnCode = 200, FileName = "test", ReturnMessage = "File Downloaded Successfully!", bse64 = base64File });
}
catch (Exception ex)
{
throw;
}
}
解决方案
推荐阅读
- r - 使用“caret”包运行决策树模型时出错
- java - 如何访问 Omnikey 3121 智能卡读卡器
- firebase - Flutter 中的 Cloud Firestore getAll() 等效项
- kubernetes - 尝试从 Web 客户端 (grpc-web) 调用 GRPC 服务器(在 GKE 上)时出现“404 未找到”
- wordpress - 古腾堡自定义元块不将元保存到自定义帖子类型
- android - 如何在颤振(android)应用程序中使用 C++ 代码?
- bash - Bash函数不回显附加参数
- sql - 分层查询显示每个父级下的所有子级
- javascript - 如何将此图像加载到自动完成文本框中?
- express - 使用 express-ntlm 身份验证对 TFS api 进行身份验证