Maximum request length exceeded error in file uploading - c#

How to upload the 5mb pdf files using html upload button?when I try upload the 5mb files I get Maximum request length exceeded error?.This problem occurs because the default value for the maxRequestLength parameter in the section of the Machine.config file is 4096 (4 megabytes).So I try to change webconfig file,
<configuration>
<system.web>
<httpRuntime maxRequestLength="102400" executionTimeout="1200" />
</system.web>
</configuration>
If i use like this i got the An existing connection was forcibly closed by the remote host error.my project is hosted with IIS7.So I try to,
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1048576" />
</requestFiltering>
</security>
</system.webServer>
This way also not allow to upload the 5mb files?How to upload the 5 mb files through HTML Upload button?

trying adding a "0" To the end of your <requestLimits maxAllowedContentLength> value. I think it's in bytes, which means your example sets it to about 1MB.
Here's the doc on this setting.

If you are running this on a shared hosting account, chances are less that you will be able to resolve this. Due to limited resource allocation, hosting providers specify the timeout for a connection so if the connection takes too much time, it closes it.
My advice is, you should seek help of your hosting provider or try changing the host or plan.

Assuming this is your own server, if not see Murtuza Kabul.
Try
requestLengthDiskThreshold="800000"
Btw I would recommend NeatUpload because the HTML Upload isn't very good in my opinion.

Related

Unable to call a HTTP POST request having a csv file more than 10000 records

I am calling a Web API from my C# code wherein I am making an HTTPPost request and sending a CSV file containing almost 11000 rows/records.
It works fine when the number of rows is less than 10,000. However, it throws a 400 bad request when records exceed 10,000.
Any suggestions?
If Web API is hosted by IIS, the default upload file size is 4MB.
To increase that limit, you could update web.config settings:
<system.web>
<httpRuntime maxRequestLength="1048576" /> <!-- KB -->
</system.web>
<!-- for IIS 7+ -->
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" /> <!-- Byte -->
</requestFiltering>
</security>
</system.webServer>
Resolved my issue. It seems there was no issue with my code to POST the records. It was third party WebAPI's restriction to upload at max 10,000 records.

Increase the maximum request length in a Azure Api App

I have created an Azure Api App which I will use to upload files. These files will be > 4mb hence the need to increase the maximum request length. I have added the following to Web.config:
<system.web>
<httpRuntime executionTimeout="7200" targetFramework="4.5" maxRequestLength="2097152" />
</system.web>
I have also added:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2097152000" />
</requestFiltering>
</security>
</system.webServer>
Yet I still get the exception Maximum request length exceeded.. Am I missing something? Is there something else I can try?
Thanks!
Unfortunately, this is not possible yet. Except the limitation on the API App, there is also a limitation on the Gateway which is an ASP.NET app as well. You can change your API App but you cannot change the Gateway.
I know the team is looking into providing a solution to that but I don't have an ETA to share at this point.

Is there an upload limit when using Web Client in C#?

Using UploadFile("upload.php", "POST", filePath) with WebClient anything over 4mb will not upload. The limit in PHP is set at 48mb. Is there I need to set in C# ?
There is a default maxRequestLength set at 4MB in ASP.NET, you can change it in the web.config.
<configuration>
<system.web>
<!-- This will handle requests up to 1024MB (1GB) -->
<httpRuntime maxRequestLength="1048576" timeout="3600" />
</system.web>
</configuration>
The length is specified in KB in the config file. If you are using IIS there is an additional limit set at 4MB by IIS.
I have solved the problem. By changing the following in the php.ini
post_max_size = 40M
I had already changed the upload_max_filesize but was not aware of this other param which needed changing.

AsyncFileUpload Change Request Size

I am currently working on an ASP.net C# web app. I am using the AjaxControlToolkit ASyncFileUpload, however, when I upload a certain file I get the error message Maximum Request Length Exceeded. Is there a way that I can increase the size limit for file uploads.
Thanks for any help you can provide.
The maximum request length is set in web.config, specifically in the httpRuntime/maxRequestLength value.
<!-- Maximum 16 MB -->
<httpRuntime maxRequestLength="16384" />
Do be aware that there might also be a limitation in IIS depending on your version.
Max request length is defined in web.config in KB as 4096 (default to 4MB), you can change the following in web.config
<system.web>
<httpRuntime maxRequestLength="51200"
enable = "True"
executionTimeout="45"/>
</system.web>
</configuration>

Try to use File.SAVEAS but get 404 error, because the size is big

I'm using asp:fileupload control to upload my Picture files. So the user click on browse and select the file and click on upload and in event handler of upload button there is FileUpload.PostedFile.SaveAs () etc.
Everything works fine. Accept when for big file size. e.g. I've got a file (jpg) 5.5 MB. When I try to upload this file I get an the error below.
The strange thing is I the button upload file eventhandler I check the file size. If (intFileesize < intFileSizeLimit) etc.
But the strange thig is I remove all the code in Upload eventhandler for testing/debugging and I still get the error below. So the error occurs outside the Button handler. I mean
the error cause is not by Fileupload.SAveAs etc.... So the question is how can I avoid this. I mean I have built restriction of 1 mb, but This code is not reached.
I don't have any problems with small sizes e.g. I could upload 400 kb w/o problem.
So the question is what is the cause for the big file size how can I solve this?
Other question is: Is there a tool or whatever to crop the filesize and upload? I mean even if they upload 6 mb picture, I should crop that to 50kb or whatever during upload. How to aproach this? maybe a 3rd party freeware?
ERROR I get after 2-3 seconds
Oops! This page appears broken. HTTP 404 - File not found.
see maxRequestLength in http://msdn.microsoft.com/en-us/library/e1f13641.aspx
The default request size is likely being reached. By default I believe ASP.NET supports a 4MB request size limit. You can change this in your config:
<system.web>
<httpRuntime executionTimeout="240" maxRequestLength="20480" />
</system.web>
The above example changes the request size to 20MB. The thing to take into consideration is that HTTP was never really designed to handle large file uploads. You may want to consider using an alternative, such as a Flash upload control...
UPDATE
For IIS7 you may need to update the configuration in the system.webServer section:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="20480" />
IIS uses the same configuration system as ASP.NET, but because it may not be an ASP.NET handler being called, it has an additional setting for other content requests.
Since you already have maxRequestLength set in the <httpRuntime> tag in web.config, it looks like you are hitting the IIS7 request filter.
Try adding this to your web.config:
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="33554432"/>
</requestFiltering>
</security>
Depending on how your server is set up, you may also need to change the IIS configuration to allow you to set up request filtering at the application level rather than the machine level. Edit %windir%\system32\inetsrv\config\applicationHost.config and change:
<section name="requestFiltering" overrideModeDefault="Deny" />
To:
<section name="requestFiltering" overrideModeDefault="Allow" />

Categories