Reputation: 1013
I have an older ASP.NET API web service using .net 4.5.2 and I am posting an object that contains a base64 image to my controller without any problem. The issues come now when I try to post data with more and larger images and I am getting the 413 request entity too large error. I have been looking up things and tried everything I could find on the net with no luck. I am looking to upload files about 10MB in size. One thing that leads me to believe its server related is when running the service under IIS Express I can upload large files locally.
I have tried adding MaxRequestLength and MaxAllowableContentLength to the web config.
<system.web>
<!-- tell IIS to let large requests through -->
<httpRuntime maxRequestLength="52428800" />
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="52428800" />
</requestFiltering>
</security>
I have also made a change on my windows 2012 R2 server in IIS v6.2 to allow larger files. I have also adjusted the UploadReadAhead value on the server.
I don't have anything special in API config class.
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml");
config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);
}
}
The bindings in my config for this service
<webHttpBinding>
<binding name="SecureServerBindingWithUserNameRest" maxReceivedMessageSize="52428800">
<readerQuotas maxArrayLength="10485760" />
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" proxyCredentialType="None" />
</security>
</binding>
<binding name="webHttpTransportSecurityRest">
<security mode="Transport" />
</binding>
</webHttpBinding>
Upvotes: 6
Views: 22527
Reputation: 2353
The "413 Payload Too Large" error typically indicates that the server has a limit on the size of the payload (data) that can be sent in a single request, and the request you're making exceeds that limit.
In your ASP.NET application, check the web.config file for the following settings and adjust them accordingly:
<system.web>
<httpRuntime maxRequestLength="your_max_file_size_in_kb" executionTimeout="seconds" />
</system.web>
Replace your_max_file_size_in_kb and seconds as per your need.
If you're using multipart requests for file uploads, check the web.config for the following settings:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="your_max_file_size_in_bytes" />
</requestFiltering>
</security>
</system.webServer>
Replace your_max_file_size_in_bytes with the maximum allowed file size in bytes.
This resolved my issue for uploading large size file. Thanks!
Upvotes: 0
Reputation: 188
When I encountered this error while sendig zipped files containing a large amount of PDFS, the solution I found was to also add to the web config requestLengthDiskThreshold apart from the maxRequestLength:
<system.web>
<httpRuntime maxRequestLength="268435456" requestLengthDiskThreshold="268435456" executionTimeout="600"/>
I also added a longer timeout than the 90 preset so it had time to send the file. Just have in mind that the requestLengthDiskThreshold must not exceed the maxRequestLength.
Upvotes: 1
Reputation: 5333
You might also consider executing a dummy get request just before posting large content. When a https connection is initialized, this first request should not be very large. Once the https connection is initialized proceeding requests are not limitted.
Upvotes: 0
Reputation: 5235
You can try this solution, try to increase the upload size limit. IIS uses uploadReadAheadSize parameter in applicationHost.config and web.config files.
system.webServer
and then serverRuntime
uploadReadAheadSize
value to 2147483647
Upvotes: 5