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)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.