va3jsl
asked on
C# .net upload large image file
Using File Upload control on a WebForm to upload a ~6Mb jpg. Get error:
[HttpException (0x80004005): Maximum request length exceeded.]
System.Web.HttpRequest.Get EntireRawC ontent() +9693899
System.Web.HttpRequest.Get MultipartC ontent() +63
System.Web.HttpRequest.Fil lInFormCol lection() +165
System.Web.HttpRequest.Ens ureForm() +75
System.Web.HttpRequest.get _Form() +12
System.Web.HttpRequest.get _HasForm() +9695295
System.Web.UI.Page.GetColl ectionBase dOnMethod( Boolean dontReturnNull) +95
System.Web.UI.Page.Determi nePostBack Mode() +69
System.Web.UI.Page.Process RequestMai n(Boolean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt) +130
I have changed the web config to:
and this is how the file is read:
[HttpException (0x80004005): Maximum request length exceeded.]
System.Web.HttpRequest.Get
System.Web.HttpRequest.Get
System.Web.HttpRequest.Fil
System.Web.HttpRequest.Ens
System.Web.HttpRequest.get
System.Web.HttpRequest.get
System.Web.UI.Page.GetColl
System.Web.UI.Page.Determi
System.Web.UI.Page.Process
I have changed the web config to:
<system.web>
<httpRuntime executionTimeout="100000" maxRequestLength="214748364" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="214748364" />
</requestFiltering>
</security>
</system.webServer>
and this is how the file is read:
int fileLength = uploadedFile.ContentLength;
byte[] buffer = new byte[fileLength];
uploadedFile.InputStream.Read(buffer, 0, fileLength);
string base64String = Convert.ToBase64String(buffer, 0, buffer.Length);
Image im = new Image();
im.ImageUrl = "data:image/png;base64," + base64String;
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
My fault. I was confused by web.config and web.debug.config.
Works fine now. Thanks
Works fine now. Thanks
ASKER
System.Web.HttpRequest.Get
I tried with:
<httpRuntime executionTimeout="100000" maxRequestLength="214000" />
<httpRuntime executionTimeout="100000" maxRequestLength="10000" />
<httpRuntime executionTimeout="10000" maxRequestLength="10000" />
Is there a timeout required in the 'security. sectionÉ
I`m developing on Visual Studio for web 2013. Is there anything in the IIS Server settings
I also tried several other files ~2MB works but ~4Mb does not.