title: Problem with C# HTTP PUT request code
body: <p>I am trying to send a file to S3 via a PUT request URL that Amazon S3 has already generated for me.</p>
  
  <p>My code works fine for small files, but it errors out on large files (>100 mb) after a few minutes of sending.</p>
  
  <p>There error is: <strong><em>The request was aborted: The request was canceled.    at System.Net.ConnectStream.InternalWrite(Boolean async, Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state)
     at System.Net.ConnectStream.Write(Byte[] buffer, Int32 offset, Int32 size)</em></strong></p>
  
  <p>Can someone please tell me what is wrong with my code that is stopping it from sending large files?  It is not due to the Amazon PUT request URL expiring because I have that set to 30 minutes and the problem occurs after just a few minutes of sending.</p>
  
  <p>The code eventually exceptions out on this line of code: <code>dataStream.Write(byteArray, 0, byteArray.Length);</code></p>
  
  <p>Once again, it works great for smaller files that I am sending to S3.  Just not large files.               </p>
  
  <pre><code>WebRequest request = WebRequest.Create(PUT_URL_FINAL[0]);
  //PUT_URL_FINAL IS THE PRE-SIGNED AMAZON S3 URL THAT I AM SENDING THE FILE TO
  
  request.Timeout = 360000; //6 minutes
  
  request.Method = "PUT";
  
  //result3 is the filename that I am sending                                     
  request.ContentType =
      MimeType(GlobalClass.AppDir + Path.DirectorySeparatorChar + "unzip" +
               Path.DirectorySeparatorChar +
               System.Web.HttpUtility.UrlEncode(result3));
  
  byte[] byteArray =
      File.ReadAllBytes(
          GlobalClass.AppDir + Path.DirectorySeparatorChar + "unzip" +
          Path.DirectorySeparatorChar +
          System.Web.HttpUtility.UrlEncode(result3));
  
  request.ContentLength = byteArray.Length;
  Stream dataStream = request.GetRequestStream();
  
  // this is the line of code that it eventually quits on.  
  // Works fine for small files, not for large ones
  dataStream.Write(byteArray, 0, byteArray.Length); 
  
  dataStream.Close();
  
  //This will return "OK" if successful.
  WebResponse response = request.GetResponse();
  Console.WriteLine("++ HttpWebResponse: " +
                    ((HttpWebResponse)response).StatusDescription);
  </code></pre>