Solved

C# .net upload large image file

Posted on 2014-12-01
3
429 Views
Last Modified: 2014-12-01
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

0
Comment
Question by:va3jsl
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
Kimputer earned 500 total points
ID: 40473929
You have an error here: <httpRuntime executionTimeout="100000" maxRequestLength="214748364" />
That's because maxRequestLength is actually in KB (while maxAllowedContentLength is indeed in Bytes).
Please try again with
<httpRuntime executionTimeout="100000" maxRequestLength="214000" />
Which is already a lot! (214MB)
0
 

Author Comment

by:va3jsl
ID: 40474057
[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.
0
 

Author Comment

by:va3jsl
ID: 40475155
My fault.  I was confused by web.config and web.debug.config.

Works fine now.  Thanks
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
a reliable reference for c+11? 3 79
Multiple image collision 13 87
Mac OS: Need a magnifying glass as an icon 7 80
insert image with its metadata into SQL server Database 3 127
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses the PaperPort 14 Scanner Connection Tool, which Nuance provides at no charge in order to fix scanning problems in Windows 8. Furthermore, users of PaperPort 14 in Windows 7 and Windows 10 have reported that the tool works in t…
The goal of the tutorial is to teach the user how to add a water mark to there photo. Once you have a photo you like you have to go into the water mark setting and add a water mark to the image. You can either choose a text watermark or an image…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question