PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 31, 2022

[FIXED] How to achieve strictly file size limit in Abp

 July 31, 2022     .net-5, abp, asp.net-web-api, file-upload     No comments   

Issue

I'm trying to set strictly file size limit using filter, in the mean while, there is already a default global setting at Startup.cs

Startup.cs

int sizeLimit = 200000;

services.Configure<IISServerOptions>(options =>
{
    options.MaxRequestBodySize = sizeLimit;
});

services.Configure<KestrelServerOptions>(options =>
{
    options.Limits.MaxRequestBodySize = sizeLimit;
});

services.Configure<FormOptions>(x => x.MultipartBodyLengthLimit = sizeLimit);

TestApiController.cs or Service(Dynamic Controller)

[Route("[controller]")]
public class TestApiController : Controller
{
    [HttpPost]
    [RequestSizeLimit(100_000)]
    [RequestFormLimits(MultipartBodyLengthLimit = 100_000)]
    public bool Post(IFormFile file)
    {
        return true;
    }
}

I found warning log when i upload file

A request body size limit could not be applied. The IHttpRequestBodySizeFeature for the server is read-only.

I seem to need to set IHttpMaxRequestBodySizeFeature IsReadOnly to false, but it can't. There's not setter at IsReadOnly.

app.Run(async (context) =>
{
    var httpMaxRequestBodySizeFeature = context.Features.Get<IHttpMaxRequestBodySizeFeature>();
    httpMaxRequestBodySizeFeature.IsReadOnly = false;
});

Then I found it will affected by IsUpgraded, If IHttpUpgradeFeature.UpgradeAsync be called will set IsUpgraded to true. I wonder this method may have called at somewhere, but i can't figure it out.

bool IHttpMaxRequestBodySizeFeature.IsReadOnly => HasStartedConsumingRequestBody || IsUpgraded;

ref IHttpUpgradeFeature.UpgradeAsync()


Solution

need to use customized attribute https://github.com/abpframework/abp/issues/12336



Answered By - Billy Chung
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing