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 MaxRequestBodySizeproperty 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 UseHttpSysMaxRequestBodySize 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的更多相关文章

  1. Nginx出现“413 Request Entity Too Large”错误解决方法

    Nginx出现“413 Request Entity Too Large”错误解决方法 2011-03-25 13:49:55|  分类: 默认分类 |  标签:413  request  entit ...

  2. nginx:413 Request Entity Too Large 及 修改 PHP上传文件大小配置

    开发环境:CentOS + Nginx + PHP + MySql + phpMyAdmin 在用 phpMyAdmin 进行 sql 数据库导入的时候,经常需要上传比较大的 sql 数据文件,而这时 ...

  3. WCF (413) Request Entity Too Large

    有网友碰到过这样的问题:wcf 远程服务器返回了意外响应: (413) Request Entity Too Large. - wsx_net,问题详细内容为:挺不错的博文:wcf 远程服务器返回了意 ...

  4. 413 Request Entity Too Large

    做小视频上传,结果接口总是返回500,服务器端跟踪,根本就进不来,再次翻查,发下服务器返回的其实是413,只不过APP底层接口将所有不是200的回包都转成500了,问题定位. 有了错误码,有了描述,字 ...

  5. nginx 出现413 Request Entity Too Large问题的解决方法

    nginx 出现413 Request Entity Too Large问题的解决方法 使用php上传图片(大小1.9M),出现 nginx: 413 Request Entity Too Large ...

  6. Nginx出现413 Request Entity Too Large错误解决方法

    Nginx出现的413 Request Entity Too Large错误,这个错误一般在上传文件的时候出现,打开nginx主配置文件nginx.conf,找到http{}段,添加 解决方法就是 打 ...

  7. Nginx:413 Request Entity Too Large解决

    最近在做给博客添加上传PDF的功能,但是在测试上传文件的过程中遇到了413 Request Entity Too Large错误.不过这个无错误是很好解决的,这个错误的出现是因为上传的文件大小超过了N ...

  8. dnmp(docker的lnmp)安装WordPress之后图片上传问题 问题:图片上传大小问题解决和 报错413 Request Entity Too Large

    首先是提示超过图片尺寸和大小, 最后发现都是图片大小的问题, 需要修改php的最大上传size 修改之后查看php配置  已经生效  但是还是报错, 提示返回不是合法的json,  查看控制台, 报错 ...

  9. Nginx配置,413 Request Entity Too Large错误解决

    今天有同事找我,说图片上传之后,不知道去哪里了.分析了一下问题,找到原因之后做了处理,这里简要记录一下. 问题原因: 1.首先后台log并无错误信息: 2.捡查了一下浏览器,发现network中有报错 ...

随机推荐

  1. windows下配置lua环境

    1.进入lua官网http://www.lua.org/ 2.点击download 3.点击get a binary 4.点击[Lua - joedf's Builds] 5.选择适合自己的版本下载, ...

  2. zookeeper开发

    环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 zookeeper-3.4.11 ZK客户端操作命令: #登 ...

  3. SQL 语法速记

    ----------------------------------DML(数据操作语言)---------------------------------- -- 一.INSERT VALUES语句 ...

  4. jar包读取jar包内部和外部的配置文件,springboot读取外部配置文件的方法

    jar包读取jar包内部和外部的配置文件,springboot读取外部配置文件的方法 用系统属性System.getProperty("user.dir")获得执行命令的目录(网上 ...

  5. Twemproxy和Redis性能压力测试

    性能测试 Redis自带了一个叫 redis-benchmark的工具来模拟N个客户端同时发出M个请求,(类似于Apache ab程序),你可以使用redis-benchmark -h来查看基准参数. ...

  6. django变量使用-在模板中使用视图函数中的变量

    DTL语言,即django template language 第一次使用时,需要修改项目的setting.py文件,将其中TEMPLATES中的DIRS修改为os.path.join(BASE_DI ...

  7. MySQL乐观锁和悲观锁的概念和原理

    乐观锁:在取数据时不加锁,等处理完逻辑的时候,查看是否与上一次相同,若相同则更新,若不同则拒绝. 悲观锁:在取数据时就加上锁,只有更新完数据之后,别的用户才可以进行读. (个人总结)

  8. windows dhcp server

    windows7并没有自带dhcp server的功能,需要安装额外的软件,软件很小巧,只有几百K字节,下载地址http://www.dhcpserver.de/cms/download/ 假设解压路 ...

  9. No symbol "xxx" in current context解决

    当gdb的版本低于相应的gcc版本的时候,就会出现debug的时候出现No symbol "*" in current context或者The address where a.o ...

  10. python简说(二十)操作excel

    一.pip install xlrdpip install xlwtpip install xlutils 二.写excel import xlwtbook = xlwt.Workbook() #新建 ...