title: Uploading Image to Imgur on Windows Phone
body: <p>I'm currently trying to build an app that involves the user selecting a photo from their library (or taking a photo) and uploading it to Imgur. I have already built a fairly robust C# Imgur client for Windows Forms applications, but unfortunately porting it to the Windows Phone has been a disaster.</p>
  
  <p>Here is the code that I am using:
  </p>
  
  <pre><code>public void UploadImageAsync(Stream PhotoStream)
  {
      try
      {
          WebClient w = new WebClient();
          w.Headers["Content-type"] = "application/x-www-form-urlencoded";
  
          string data = "key="+PublicKey+
                  "&amp;_fake_status=200"+
                  "&amp;type=base64"+
                  "&amp;image="+PhotoStreamToBase64(PhotoStream);
  
          w.UploadStringAsync(new Uri("http://api.imgur.com/2/upload", UriKind.Absolute), "POST", data);
  
      }
      catch (Exception ex)
      {
      }
  }
  
  string PhotoStreamToBase64(Stream PhotoStream)
  {
      MemoryStream memoryStream = new MemoryStream();
      PhotoStream.CopyTo(memoryStream);
      byte[] result = memoryStream.ToArray();
      return System.Convert.ToBase64String(result);
  }
  </code></pre>
  
  <p>What is interesting (and frustrating) is that it appears as though everything is working fine, and I receive a successful response after the upload has completed. However, when trying to view the image after being uploaded, the result looks like this: <a href="http://i.imgur.com/NWY0R.jpg" rel="nofollow">http://i.imgur.com/NWY0R.jpg</a>.</p>
  
  <p>This leads me to believe that somehow the image stream is being converted into the byte array incorrectly, or converted into a base 64 string incorrectly. In any case, I cannot get it to work and I am at a total loss. Does anybody have any idea? Any help would be greatly appreciated.</p>