title: IMGUR photo upload POST Request
body: <p>what im trying to do is to make photo upload to imgur site using their API here <a href="http://api.imgur.com/endpoints/image#image-upload" rel="nofollow">http://api.imgur.com/endpoints/image#image-upload</a>. As i read in documentation, image data has to be in "image" parameter. So what im doing is setting POST request data as "image=base64codedfile&amp;title=blabla&amp;type=base64" and it does upload it but file is corrupted. If my request will contain only "base64codedfile" without image, title, type name parameters its working like a charm. Am i doing something wrong?</p>
  
  <p>If i set it as:</p>
  
  <pre><code>string postData = "image="+Convert.ToBase64String(image)+"&amp;type=base64&amp;title=test;
  </code></pre>
  
  <p>image is corrupted</p>
  
  <p>If it's only raw data:</p>
  
  <pre><code>string postData = Convert.ToBase64String(image);
  </code></pre>
  
  <p>It's working</p>
  
  <p>Whole code is something like this:</p>
  
  <pre><code>HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.imgur.com/3/upload.xml");
  request.Headers.Add("Authorization", "Client-ID &gt;&gt;myclientid&lt;&lt;");
  request.Method = "POST";
  
  string filePath = "d:\\test.jpg";
  FileStream file = new FileStream(filePath, FileMode.Open);
  byte[] image = new byte[file.Length];
  file.Read(image, 0, (int)file.Length);
  ASCIIEncoding enc = new ASCIIEncoding();
  string postData = Convert.ToBase64String(image);
  byte[] bytes = enc.GetBytes(postData);
  
  request.ContentType = "application/x-www-form-urlencoded";
  request.ContentLength = bytes.Length;
  
  Stream writer = request.GetRequestStream();
  writer.Write(bytes, 0, bytes.Length);
  
  HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  </code></pre>