Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Request body too large

When I try to upload a 80mb file from postman to my local endpoint running in Visual Studio 2019 on IISExpress I get the following error:

The request filtering module is configured to deny a request that exceeds the request content length.

So I added this to applicationhost.config for the project:

<system.web>
      <httpRuntime maxRequestLength="1050000" /> 
    </system.web>
    <system.webServer>
        <security>
            <requestFiltering>
                <requestLimits maxAllowedContentLength="1073741824"/>
            </requestFiltering>
        </security>

This stop the error coming when I make the API request but now I just get a ServiceStack generated "snapshot" page telling me how long request took and the date but my actual endpoint is never hit.

Inside my logs I can see ServiceStack throwing this exception:

2020-07-20 01:57:56.0497||ERROR|ServiceStackHost|Request body too large. Microsoft.AspNetCore.Server.IIS.BadHttpRequestException: Request body too large. at Microsoft.AspNetCore.Server.IIS.BadHttpRequestException.Throw(RequestRejectionReason reason) at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.InitializeRequestIO() at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.ReadAsync(Memory1 memory, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.IIS.Core.HttpRequestStream.ReadAsyncInternal(Memory1 buffer, CancellationToken cancellationToken) at Microsoft.AspNetCore.WebUtilities.BufferedReadStream.EnsureBufferedAsync(Int32 minCount, CancellationToken cancellationToken) at Microsoft.AspNetCore.WebUtilities.MultipartReaderStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken) at Microsoft.AspNetCore.WebUtilities.StreamHelperExtensions.DrainAsync(Stream stream, ArrayPool1 bytePool, Nullable1 limit, CancellationToken cancellationToken) at Microsoft.AspNetCore.WebUtilities.MultipartReader.ReadNextSectionAsync(CancellationToken cancellationToken) at Microsoft.AspNetCore.Http.Features.FormFeature.InnerReadFormAsync(CancellationToken cancellationToken) at Microsoft.AspNetCore.Http.Features.FormFeature.ReadForm() at Microsoft.AspNetCore.Http.DefaultHttpRequest.get_Form() at ServiceStack.Host.NetCore.NetCoreRequest.get_FormData() in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\Host\NetCore\NetCoreRequest.cs:line 167 at ServiceStack.HttpRequestExtensions.GetFlattenedRequestParams(IRequest request) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\HttpRequestExtensions.cs:line 555 at ServiceStack.Host.RestHandler.CreateRequestAsync(IRequest httpReq, IRestPath restPath) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\Host\RestHandler.cs:line 132 at ServiceStack.Host.RestHandler.ProcessRequestAsync(IRequest req, IResponse httpRes, String operationName) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\Host\RestHandler.cs:line 89|url: |action:

So the Body length still needs to be set somewhere but everywhere I look points back to the config I have already used.

Is there additional setting required or is this a ServiceStack issue?

like image 262
Guerrilla Avatar asked Jul 20 '20 01:07

Guerrilla


People also ask

What does “ 413 request entity too large” mean?

What does “413 Request Entity Too Large” mean? A 413 HTTP error code occurs when the size of a client’s request exceeds the server’s file size limit. This typically happens when a client attempts to upload a large file to a web server, and the server responds with a 413 error to alert the client. Web servers place size limits on uploads ...

What is the Max request body size limit in useiis?

I have also tried everything descried here: New default 30 MB (~28.6 MiB) max request body size limit but no luck. Receiving same error. Thank you. app. UseIIS ( options => { options. MaxRequestBodySize = 1048576000 ; });

Why am I getting an Azure Storage request body error?

In this scenario, the following error is returned: Message: The request body is too large and exceeds the maximum permissible limit. There's a 4-MB limit for each call to the Azure Storage service. If your file is larger than 4 MB, you must break it in chunks. For more information, see Azure Storage scalability and performance targets.

What does 404 Bad request header or cookie too large mean?

Similarly, the 404 Bad Request “ Request Header Or Cookie Too Large ” error is common in websites that use the Nginx web server. This error appears if your cookies are corrupted or your website cookie is larger than the limit accepted by the website. So, in this article, we’ll show you how to fix this error.


1 Answers

I was missing this option in startup:


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

services.Configure<KestrelServerOptions>(options =>
{
    options.Limits.MaxRequestBodySize = int.MaxValue; // if don't set default value is: 30 MB
});

like image 148
Guerrilla Avatar answered Oct 12 '22 20:10

Guerrilla