Link to home
Create AccountLog in
Avatar of va3jsl
va3jslFlag for Canada

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.GetEntireRawContent() +9693899
   System.Web.HttpRequest.GetMultipartContent() +63
   System.Web.HttpRequest.FillInFormCollection() +165
   System.Web.HttpRequest.EnsureForm() +75
   System.Web.HttpRequest.get_Form() +12
   System.Web.HttpRequest.get_HasForm() +9695295
   System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) +95
   System.Web.UI.Page.DeterminePostBackMode() +69
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +130


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>

Open in new window



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;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Kimputer
Kimputer

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of va3jsl

ASKER

[HttpException (0x80004005): Maximum request length exceeded.]
   System.Web.HttpRequest.GetEntireRawContent() +9693899

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.
Avatar of va3jsl

ASKER

My fault.  I was confused by web.config and web.debug.config.

Works fine now.  Thanks