Is there an upload limit when using Web Client in C#? - 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.

Related

HttpException: maximum request length exceeded, even when config has values that should allow it

I can't seem to allow a 4.3MB upload. I keep getting this error:
System.Web.HttpException (0x80004005): Maximum request length
exceeded.
My web.config settings in my Web API:
<!-- maxRequestLength expresses POST buffer size in KB. This is the ASP.NET limit. -->
<httpRuntime targetFramework="4.5" maxRequestLength="20000" />
<!-- Let this be larger than maxRequestLength so we get ASP.NET error (if request too large) instead of IIS error. -->
<requestLimits maxAllowedContentLength="20480000" />
And this is the call to the API from my web project:
var response = await httpClient.SendAsync(proxyRequest);
That always returns the above error. What am I missing? I did read where maxRequestLength needs to be the same value as maxAllowedContentLength, but that didn't work either.
The "Default Web Site" in IIS had a config file with almost nothing in it. I added maxRequestLength="20000" to it and it worked. My app is one of many apps under "Default Web Site."
Added this:
<system.web>
<httpRuntime targetFramework="4.5" maxRequestLength="20000" />
</system.web>

Maximum request length exceeded error in file uploading

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.

maxItemsInObjectGraph in asp.net web service?

A client of ours is using an asp.net web service (asmx) I created and is getting an error saying the maxItemsInObjectGraph is too small. I told him to make the necessary changes in his app.config file. But where do I have to make these changes on my side?? The web.config file in my web service doesn't mention maxItemsInObjectGraph.
Thanks a lot.
Because it has a default value which is used when it's not in your config. You'll have to either add it to your web.config or to your code as shown here, here, here or here.
EDIT: For ASMX there isn't a setting for maxItemsInObjectGraph, setting the maximum request length might help though.
<location path="yourservice.asmx">
<system.web>
<httpRuntime executionTimeout="240" maxRequestLength="20480" />
</system.web>
</location>
Other properties for the httpRuntime on MSDN

Uploading file size over 4 MB in .NET

I am having trouble uploading a file size over 4 MB. I've tried adding
<httpRuntime maxRequestLength="102400" executionTimeout="99999" />
to my Web.Config like many posts have suggested, but it just isn't working. Files under 4 MB work just fine, so I'm nearly certain I'm running into the 4 MB limit. Are there any settings in IIS that I might need to change?
You need to update the value of maxrequestlength in the web.config:
Maximum value of maxRequestLength?
Max Request Length
You can use that code into your web.config file.
<system.web>
<httpRuntime executionTimeout="3600" maxRequestLength="102400000000"
appRequestQueueLimit="100000" requestValidationMode="4.0"
requestLengthDiskThreshold="10024000000000"/>
</system.web>
I think it will work

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>

Categories