1. Add the following code to startup
public void ConfigureServices(IServiceCollection services) { services.Configure<FormOptions>(options => { // Set the limit to 256 MB options.MultipartBodyLengthLimit = 268435456; }); }
2. Add in program
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.ConfigureKestrel((context, options) => { // Handle requests up to 50 MB options.Limits.MaxRequestBodySize = 52428800; }) .UseStartup<Startup>(); });
3. Adding a property to an action method
// Handle requests up to 50 MB [RequestSizeLimit(52428800)] public ActionResult<ResultDto<bool>> AddFile() { ... }
I recommend the first one and write the size limit to the configuration file.
Similar Posts:
- How to Solve C# upload Large File Error
- [Solved] pipenv shell:AttributeError: ‘module’ object has no attribute ‘run’
- NPM Command Error: Allocation failed – JavaScript heap out of memory
- Container Cannot Find bean, Field usersMapper in com.imooc.impl.UserServiceImpl required a bean of type ‘com.imooc.mapper.UsersMapper’ that could not be found.
- [LeetCode] 291. Word Pattern II
- Nacos: How to Solve failed to req API:/nacos/v1/ns/instance after all servers([127.0.0.1:8848])
- How to Solve .Net 5 webapi cross domain Issue
- Summary of SSH error reporting and solution records
- Spring cloud uses feignclient to start and report an error