Solved

C# .net upload large image file

Posted on 2014-12-01
3
446 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 36

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I. Introduction In a previous article (http://www.experts-exchange.com/Web_Development/Document_Imaging/A_6537-PaperPort-Upgrade-How-to-download-and-install-updated-versions-of-PaperPort-11-and-12.html) (now deprecated), I discussed how to upgrad…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
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…
The goal of the tutorial is to teach the user how to edit a basic portrait of someone. This tutorial shows how to edit two basic photographs, one of a car and one of a person.

696 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