Solved

C# .net upload large image file

Posted on 2014-12-01
3
403 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
Comment Utility
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
Comment Utility
[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
Comment Utility
My fault.  I was confused by web.config and web.debug.config.

Works fine now.  Thanks
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

PaperPort is a popular document imaging/management product from Nuance Communications (http://www.nuance.com/). It is in widespread use by both individuals (http://www.nuance.com/for-individuals/by-product/paperport/index.htm) and businesses (http:/…
This article shows how to convert a multi-page PDF file into multiple image files, with one image file created for each page of the PDF. It does this by utilizing an excellent, free software package called GraphicsMagick. The solution is amazingly s…
Users will learn how resize a batch of photos from a single command in Photoshop via Photoshop's Image Processor. Open up an Image you'd like to resize in Adobe Photoshop: Adjust the image size according to your preferences. Image > Adjustments > …
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now