title: asp.net uploading big files: throws System.OutOfMemoryException
body: <p>I'd like to upload big files via ASP.NET to WCF service. Until 100 MB is not a problem, my configuration works perfectly, but above 100 MB it throws System.OutOfMemoryException.</p>
  
  <p>The uploading method works with FileStream, but before that, I save the file to a temporary folder. Not sure if this is the problem, or something else. I add the code of my controller, which takes care of calling the wcf service.</p>
  
  <pre><code>[HttpPost]
      public ActionResult Upload()
      {
          if (Request.Files.Count &gt; 0)
          {
              var file = Request.Files[0];
  
              if (file != null &amp;&amp; file.ContentLength &gt; 0)
              {
                  string fileName = Path.GetFileName(file.FileName);
                  var path = Path.Combine(Server.MapPath("~/App_Data/Images"), fileName);
  
                  file.SaveAs(path);
  
                  FileStream fsSource = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
  
                  TileService.TileServiceClient client = new TileService.TileServiceClient();
                  client.Open();
                  client.UploadFile(fileName, fsSource);
                  client.Close();
  
                  fsSource.Dispose();
                  if (System.IO.File.Exists(path))
                  {
                      System.IO.File.Delete(path);
                  }
              }
          }
  
          return RedirectToAction("");
      }
  </code></pre>
  
  <p>The method is called like this:</p>
  
  <pre><code>@using (Html.BeginForm("Upload", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
  {
  &lt;input type="file" name="FileUploader" /&gt;
  &lt;br /&gt;
  &lt;input type="submit" name="Submit" id="Submit" value="Upload file" /&gt;
  }
  </code></pre>
  
  <p>In the ASP.NET web.config I already set the following things: <em>executionTimeout, maxRequestLength, requestLengthDiskThreshold, maxAllowedContentLength</em>. I add the binding part of the configuration.</p>
  
  <pre><code>&lt;basicHttpBinding&gt;
      &lt;binding name="BasicHttpBinding_ITileService"
        closeTimeout="24:01:00" openTimeout="24:01:00" receiveTimeout="24:10:00" sendTimeout="24:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="4294967295" maxBufferSize="2147483647" maxReceivedMessageSize="4294967295" textEncoding="utf-8" transferMode="Streamed" useDefaultWebProxy="true" messageEncoding="Text"&gt;
        &lt;readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /&gt;
        &lt;security mode="None"&gt;
          &lt;transport clientCredentialType="None" proxyCredentialType="None" realm="" /&gt;
          &lt;message clientCredentialType="UserName" algorithmSuite="Default" /&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
    &lt;/basicHttpBinding&gt;
  </code></pre>