Reputation: 137
I've got an Angular application where I'm trying to use ng2-file-upload to upload files to my server and I keep getting a 413 error back when the file is large. I expect it's a server-side issue, but I'm mentioning the client-side in case anyone has seen this issue with that uploader before.
My server application is a .NET7 web app, but I'm compiling the Angular app into the wwwroot directory of the application and I've added web.config to allow me to add rewrite rules to support them within the same system.
So far, I've added: In web.config,
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="50000000" />
</requestFiltering>
</security>
<serverRuntime uploadReadAheadSize="50000000" />
</system.webServer>
<system.web>
<httpRuntime maxRequestLength="50000" />
</system.web>
On my upload endpoint,
[RequestSizeLimit( 50_000_000 )]
// or
[DisableRequestSizeLimit]
In Program.cs,
var builder = WebApplication.CreateBuilder( args );
/* ..... */
builder.Services
.Configure<FormOptions>( x =>
{
x.ValueLengthLimit = 50000000;
x.MultipartBodyLengthLimit = 50000000; // in case of multipart
x.MultipartHeadersLengthLimit = 50000000;
} )
.Configure<IISServerOptions>( x =>
{
x.MaxRequestBodySize = 50000000;
} );
/* ..... */
var app = builder.Build()
/* ..... */
app.Use( async ( context, next ) =>
{
var feature = context.Features.Get<IHttpMaxRequestBodySizeFeature>();
if( feature != null )
feature.MaxRequestBodySize = 50000000;
await next.Invoke();
} );
Any other ideas on what I'm missing? Is there something that I need to add to allow web.config to get picked up? Do I need to be putting the C# changes in a certain order (relative to other settings) in order for them to take effect?
Right now, I'm trying to get this working in my development environment (IIS Express run out of VS 2022). I'll need it working in an Azure App Service eventually, if that makes any difference on how I approach the solution.
Thoughts?
Upvotes: 0
Views: 484
Reputation: 5215
You can try to set the uploadReadAheadSize value in iis to solve this problem:
Upvotes: 0