file upload fails with "Maximum request length exceeded." - c#

I have a service that keeps failing with the above error. There are numerous posts and article's about the default size for file being 4mb and to increase the size via the web.config file. In my case the file size is 3.2mb so wouldn't expect to get this error. If I Increase the limit via the maxRequestLength attribute and the maxAllowedContentLength then this error is overcome. However, I'm trying to understand why I mighty be getting this error in the first place given that the filesize is below the 4mb limit. The file is an xml file and I'm posting to my service via postman.

Related

ASP.NET throwing 404 for large file and 400 for extremely large files

Currently writing an API that accepts files using multipart/form-data. Below are my settings in Web.config. IIS is set to 1.0737GB limit and .NET is set to a 1.0485GB limit.
<httpRuntime requestValidationMode="2.0" maxRequestLength="1048576" executionTimeout="1000000" targetFramework="4.7.1" />
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
When I upload a file around 1.5-2GB in size I get a 404 back as described in the Microsoft documentation linked below. This is my expected response from the server. But, when I upload a much larger file, around 2.5GB+, I get a 400 Bad Request instead. I have been looking around for documentation to describe why this would happen and why I would not expect to always see a 404 instead, but have found nothing stating a 400 could be returned. The only difference between the requests is the files attached, nothing else is changed. To make the larger file size I also just zipped two of the original file that throws the 404 together. As additional details, the endpoint is covered in Unit and Integration tests that verify normal use case functionality. The endpoint works when manually tested with files below the IIS/.NET set limits. This behavior has also been seen when manually tested with a C# library project as well as Postman. Any help is greatly appreciated, thanks in advance!
https://learn.microsoft.com/en-us/iis/configuration/system.webserver/security/requestfiltering/
Clarification on my use case:
A clarification is that I'm not trying to increase the size limit of my requests, I just need to make sure anything over the size limit returns the same error. The documentation that will be publicly available needs to state the return value in case of error and currently it can be either a 404 or a 400 and I can't explain explicitly why in the documentation yet.
Thanks to help from all of the commenters, the following link provided by Brian Clink answered the question. https://sitecore.stackexchange.com/questions/11788/sitecore-media-file-upload-above-2gb-throws-bad-request-400
IIS forces the max size to be 2GB. So, for all requests less than 2GB that are larger than your custom IIS settings a 404.13 is returned. For all requests over 2GB a 404 is returned.

502 response when uploading large files to asp4 site

Our site is able to handle files up to what seems 100mb.
When I upload a 100mb file, I receive the 502 bad gateway error after about 2 minutes and 20 seconds
When I upload a 200mb file, I receive the 502 bad gateway error after about 4 minutes
The above are only happening when <compilation debug="false".../>
When I set the <compilation debug="true".../> it succeeds
In my web.config I've got settings for both maxRequestLength and maxAllowedContentLength set to over a gig. I've also tried the executionTimeout setting, and it seems to have no effect.
I'm curious though in both the ~2 minute and ~4 minute requests that result in an error response... I can see that the server is actually doing the work with the file being uploaded. It's taking it, and putting it on a file share successfully and it's also going through and entering a row in our DB to track it... but it responds with a 502.
Running locally or running with <compilation debug="true".../> succeeds, if that helps at all.

Find out the max file upload size allowed on server

I have an image upload tool and I want to report an error before the file is uploaded if the size is too large for my server.
Is there a c# ASP .NET MVC 5 command for finding out this size?
I don't know if it makes a difference but i'm hosted with Microsoft Azure.
You server application can to know this value, by reading Web.config:
var section = ConfigurationManager.GetSection("system.web/httpRuntime") as HttpRuntimeSection;
// Value in KBs. 4096 means 4Mb.
var maxRequestLength = section.MaxRequestLength;
You'd have to write a controller action that queried the IIS configuration and returned the value to the client.
The client would need to call this method to find out the limit before attempting the upload.
A way to find out the value is described here:
How to read maxAllowedContentLength

Uploading a large file in ASP.net MVC

I am trying to upload a file in ASP.net MVC and want to give a user a message that "You have exceeded maximum file size" if user exceeds the maximum file size but when I try to upload a large file it gives me Httpstatus code as 200 when i checked IIS logs there are 2 request logged in IIS one is HttpStatusCode 302 and another as 200.I am not doing any kind of redirect but IIS logs are giving me 302.How can I generate 404.13 error for these kind of request and how can I track this error so that I can give a meaningful message.
Using the HTML5 File API,
var size = document.getElementById('myFile').files[0].size;
Try this plugin Blueimp jquery file upload
u can see the plugin configuration here.it has an option of setting the max file size so that u can alert the user before a server round-trip.

ReadResponse() failed: When uploading large amounts of data

I came across an issue today when adding an upload data modification to a ASP.NET 3.5 C# Web App. The user needs to upload a spreadsheet with a .xls extension containing large amounts of data. That spreadsheet will be converted to a datatable and then inserted into SQL Via a SqlBulkInsert method. The problem I am having is the sheet I am currently working with has 16 columns and can only contain 24889 rows before I receive this message from the server via Fiddler, 'ReadResponse() failed: The server did not return a response for this request.' I've searched and not found much info on this related to my issue. Any help would be appreciated.
Try giving some values for maxRequestLength like below
<system.web>
<!-- ... -->
<httpRuntime maxRequestLength="204800"/>
<!-- ... -->
</system.web>
By default you can upload a file upto 4MB.
The size of your excel must be excedding the limit.
What you can do is set the setting in Web Configuration file
What this will do is increase the request size that server can respond to.
You need to look into server logs to figure out what cases it (or simply debug the server portion if you can). You also should see if it cased by simply size of the file or data in the file (if you do any processing).
Possible reasons:
you code gets the data, but fails in some way likely tearing down whole process
ASP.Net blocks request due to size (see Pankaj Garg answer).
your code is just too slow

Categories