title: File upload to WebAPI & Azure throws HttpException
body: <p>Sometimes I get this exception when users from China upload small files (100-200kB) to a WebAPI service that passes the file straight into an Azure blob:</p>
  
  <pre><code>System.Web.HttpException: The client is disconnected because the underlying request has been completed. There is no longer an HttpContext available.
  </code></pre>
  
  <p>The controller code looks like this:</p>
  
  <pre><code>[HttpPost]
  public async Task&lt;IHttpActionResult&gt; Upload()
  {
      var stream = await Request.Content.ReadAsStreamAsync();
  
      var guid = Guid.NewGuid().ToString();
      var blob = /*CloudBlobContainer*/.GetBlockBlobReference(guid);
  
      blob.Properties.ContentType = Request.Content.Headers.ContentType.MediaType;
      blob.UploadFromStream(stream);
  
      return Ok(guid);
  }
  </code></pre>
  
  <p>And the stacktrace:</p>
  
  <pre><code>System.Web.HttpException: The client is disconnected because the underlying request has been completed.  There is no longer an HttpContext available.
  
  at System.Web.HttpBufferlessInputStream.Read(Byte[] buffer, Int32 offset, Int32 count)
  
  at System.Web.Http.WebHost.SeekableBufferedRequestStream.Read(Byte[] buffer, Int32 offset, Int32 count)
  
  at Microsoft.WindowsAzure.Storage.Core.Util.StreamExtensions.WriteToSync[T](Stream stream, Stream toStream, Nullable`1 copyLength, Nullable`1 maxLength, Boolean calculateMd5, Boolean syncRead, ExecutionState`1 executionState, StreamDescriptor streamCopyState)
  
  at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.UploadFromStreamHelper(Stream source, Nullable`1 length, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
  
  at .Controllers.FileController.&lt;Upload&gt;d__5.MoveNext()
  </code></pre>
  
  <p>Is it safe to assume this is <em>just</em> the bad internet connection? In that case I could catch and ignore it. The client has a safe re-try mechanism in case an upload went wrong.</p>
  
  <p>Or is something wrong with my code?</p>