title: uploading image to imgur using c#
body: <p>Uploading image to <a href="http://imgur.com/" rel="nofollow">imgur.com</a> using code below returns http 400 error code. My developer key is correct and I tried different image formats with sizes upto 70 kb. 
  I also tried code example for c# given at <a href="http://api.imgur.com/examples" rel="nofollow">http://api.imgur.com/examples</a> but it also gives http 400. 
  What might be the problem?</p>
  
  <pre><code>public XDocument Upload(string imageAsBase64String)
  {
      XDocument result = null;
      using (var webClient = new WebClient())
      {
          var values = new NameValueCollection
          {
              { "key", key },
              { "image", imageAsBase64String },
              { "type", "base64" },
          };
          byte[] response = webClient.UploadValues("http://api.imgur.com/2/upload.xml", "POST", values);
          result = XDocument.Load(new MemoryStream(response));
      }
      return result;
  }
  </code></pre>
  
  <p>EDIT: This is an ASP.NET MVC application and caller controller action is:</p>
  
  <pre><code>[HttpPost]
  public ActionResult UploadImage(HttpPostedFileBase uploadFile)
  {
      if (uploadFile.ContentLength &gt; 0)
      {
          var imgService = new ImgUrImageService();
          byte[] fileBytes = new byte[uploadFile.InputStream.Length];
          Int64 byteCount = uploadFile.InputStream.Read(fileBytes, 0, (int)uploadFile.InputStream.Length);
          uploadFile.InputStream.Close();
          string fileContent = Convert.ToBase64String(fileBytes, 0, fileBytes.Length);
          var response = imgService.Upload(fileContent);
      }
      return View();
  }
  </code></pre>