.net core 问题:413 Request Entity Too Large nginx
https://stackoverflow.com/questions/38698350/increase-upload-file-size-in-asp-net-core
The other answers solve the IIS restriction. However, as of ASP.NET Core 2.0, Kestrel serveralso imposes its own default limits.
Github of KestrelServerLimits.cs
Announcement of request body size limit and solution (quoted below)
MVC Instructions
If you want to change the max request body size limit for a specific MVC action or controller, you can use the RequestSizeLimit
attribute. The following would allow MyAction
to accept request bodies up to 100,000,000 bytes.
[HttpPost]
[RequestSizeLimit(100_000_000)]
public IActionResult MyAction([FromBody] MyViewModel data)
{
[DisableRequestSizeLimit]
can be used to make request size unlimited. This effectively restores pre-2.0.0 behavior for just the attributed action or controller.
Generic Middleware Instructions
If the request is not being handled by an MVC action, the limit can still be modified on a per request basis using the IHttpMaxRequestBodySizeFeature
. For example:
app.Run(async context =>
{
context.Features.Get<IHttpMaxRequestBodySizeFeature>().MaxRequestBodySize = 100_000_000;
MaxRequestBodySize
is a nullable long. Setting it to null disables the limit like MVC's [DisableRequestSizeLimit]
.
You can only configure the limit on a request if the application hasn’t started reading yet; otherwise an exception is thrown. There’s an IsReadOnly
property that tells you if the MaxRequestBodySize
property is in read-only state, meaning it’s too late to configure the limit.
Global Config Instructions
If you want to modify the max request body size globally, this can be done by modifying a MaxRequestBodySize
property in the callback of either UseKestrel
or UseHttpSys
. MaxRequestBodySize
is a nullable long in both cases. For example:
.UseKestrel(options =>
{
options.Limits.MaxRequestBodySize = null;
or
.UseHttpSys(options =>
{
options.MaxRequestBodySize = 100_000_000;
You must configure two things:
In your Program.cs
public static IWebHost BuildWebhost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseKestrel(options => {
options.Limits.MaxRequestBodySize = null; // or a given limit
})
.Build();
In your Startup.cs in the ConfigureService method
services.Configure<FormOptions>(options => options.MultipartBodyLengthLimit = long.MaxValue); // or other given limit
Also change your controller endpoint to use [FromForm]
public IActionResult Upload([FromForm] IEnumerable<IFormFile> files)... // name must be same as name attribute of your multipart form
Now ASP.NET Core will do the work and inject the files from the form as sequence.
Edit:
I created an example that can be cloned from github:
git clone https://github.com/Birdperson90/example-fileupload-aspnet-core.git
cd example-fileupload-aspnet-core
dotnet restore
dotnet run --project src/file-upload-api/file-upload-api.csproj
Then navigate to http://localhost:5000/index.html and try uploading huge files.
413 error with Kubernetes and Nginx ingress controller
You can use the annotation nginx.ingress.kubernetes.io/proxy-body-size
to set the max-body-size option right in your Ingress object instead of changing a base ConfigMap.
Here is the example of usage:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: my-app
annotations:
nginx.ingress.kubernetes.io/proxy-body-size: "50m"
...
.net core 问题:413 Request Entity Too Large nginx的更多相关文章
- Nginx出现“413 Request Entity Too Large”错误解决方法
Nginx出现“413 Request Entity Too Large”错误解决方法 2011-03-25 13:49:55| 分类: 默认分类 | 标签:413 request entit ...
- nginx:413 Request Entity Too Large 及 修改 PHP上传文件大小配置
开发环境:CentOS + Nginx + PHP + MySql + phpMyAdmin 在用 phpMyAdmin 进行 sql 数据库导入的时候,经常需要上传比较大的 sql 数据文件,而这时 ...
- WCF (413) Request Entity Too Large
有网友碰到过这样的问题:wcf 远程服务器返回了意外响应: (413) Request Entity Too Large. - wsx_net,问题详细内容为:挺不错的博文:wcf 远程服务器返回了意 ...
- 413 Request Entity Too Large
做小视频上传,结果接口总是返回500,服务器端跟踪,根本就进不来,再次翻查,发下服务器返回的其实是413,只不过APP底层接口将所有不是200的回包都转成500了,问题定位. 有了错误码,有了描述,字 ...
- nginx 出现413 Request Entity Too Large问题的解决方法
nginx 出现413 Request Entity Too Large问题的解决方法 使用php上传图片(大小1.9M),出现 nginx: 413 Request Entity Too Large ...
- Nginx出现413 Request Entity Too Large错误解决方法
Nginx出现的413 Request Entity Too Large错误,这个错误一般在上传文件的时候出现,打开nginx主配置文件nginx.conf,找到http{}段,添加 解决方法就是 打 ...
- Nginx:413 Request Entity Too Large解决
最近在做给博客添加上传PDF的功能,但是在测试上传文件的过程中遇到了413 Request Entity Too Large错误.不过这个无错误是很好解决的,这个错误的出现是因为上传的文件大小超过了N ...
- dnmp(docker的lnmp)安装WordPress之后图片上传问题 问题:图片上传大小问题解决和 报错413 Request Entity Too Large
首先是提示超过图片尺寸和大小, 最后发现都是图片大小的问题, 需要修改php的最大上传size 修改之后查看php配置 已经生效 但是还是报错, 提示返回不是合法的json, 查看控制台, 报错 ...
- Nginx配置,413 Request Entity Too Large错误解决
今天有同事找我,说图片上传之后,不知道去哪里了.分析了一下问题,找到原因之后做了处理,这里简要记录一下. 问题原因: 1.首先后台log并无错误信息: 2.捡查了一下浏览器,发现network中有报错 ...
随机推荐
- 转:wcf大文件传输解决之道(1)
首先声明,文章思路源于MSDN中徐长龙老师的课程整理,加上自己的一些心得体会,先总结如下: 在应对与大文件传输的情况下,因为wcf默认采用的是缓存加载对象,也就是说将文件包一次性接受至缓存中,然后生成 ...
- 转:[你必须知道的异步编程]——异步编程模型(APM)
本专题概要: 引言 你知道APM吗? 你想知道如何使用异步编程模型编写代码吗? 使用委托也可以实现异步编程,你知道否? 小结 一.引言 在前面的C#基础知识系列中介绍了从C#1.0——C#4.0中一些 ...
- 【JavaScript 6连载】一、关于对象(访问)
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- 一篇关于蓝牙SDP和L2CAP协议的文章
SDP地址:http://www.cnblogs.com/strive-forever/archive/2011/11/04/2236640.html L2CAP地址:http://www.cnblo ...
- vue style 的scoped 使用
1 原理 vue 可以通过在 style标签添加scoped这个属性来控制 组件内的css作用域 <style scoped> @media (min-width: 250px) { .l ...
- js 显示刚刚上传的图片 (onchange事件)
<table> <tr width="100"> <td>上传商场图片:</td> <td> <input typ ...
- 前端异步的一种方法库:axios
关于axios,其实原本在做开发的几年里并不知道,一直使用的也都是jquery的ajax.后来因为一个同事的述说,我才知道有这么个库,基于promise的http库. 看来,以前的我确实比较井底之蛙了 ...
- nginx+php+memcache实现hash一致性memcache 集群
我们工作中可能会遇到key-value数据库,如果我们面对的不止一台memcache服务器,而是很多台.那么现在就回出现一个问题: 当我们访问nginx服务器的时候,我们会判断memcache中是否有 ...
- ztree实现表格风格的树状结构
zTree官方api: http://www.treejs.cn/v3/api.php 原理很简单:利用zTree的addDiyDom方法,自定义每个DOM节点,在原来的节点后面加一些div,再利用c ...
- python静态属性@property、类方法@classmethod、静态方法@staticmethod和普通方法
静态属性:即将类的函数通过@property属性封装,封装后实例调用该函数时,不再需要在函数后面加(),而是用类似调用数据属性的方式直接调用函数名称即可执行函数. 静态属性既可以访问类的属性,也可以访 ...