title: Upload image using HttpClient
body: <p>I want to upload a file using HttpClient to a php script to save it on a server in a Windows Phone 8.1 application.</p>
  
  <p>Here is my C# code I got from <a href="https://stackoverflow.com/questions/16416601/c-sharp-httpclient-4-5-multipart-form-data-upload">this post</a>.</p>
  
  <pre><code>private async Task&lt;string&gt; GetRawDataFromServer(byte[] data)
  {
      //Debug.WriteLine("byte[] data length:" + Convert.ToBase64String(data).Length);
      var requestContent = new MultipartFormDataContent();
      //    here you can specify boundary if you need---^
      var imageContent = new ByteArrayContent(data);
      imageContent.Headers.ContentType =
          MediaTypeHeaderValue.Parse("image/jpeg");
  
      requestContent.Add(imageContent, "image", "image.jpg");
      using (var client = new HttpClient())
       {
  
           client.BaseAddress = new Uri("http://www.x.net/");
  
          var result = client.PostAsync("test/fileupload.php", requestContent).Result;
  
           return result.Content.ReadAsStringAsync().Result;
  
       }
  }
  </code></pre>
  
  <p>And with this code I retrieve the data in the php script</p>
  
  <pre><code>&lt;?
  function base64_to_image( $imageData, $outputfile ) {
      /* encode &amp; write data (binary) */
      $ifp = fopen( $outputfile, "wb" );
      fwrite( $ifp, base64_decode( $imageData ) );
      fclose( $ifp );
      /* return output filename */
      return( $outputfile );
  }       
  
  if (isset($_POST['image'])) {
      base64_to_jpeg($_POST['image'], "image.jpg");
  }
  else
      die("no image data found");
  ?&gt;
  </code></pre>
  
  <p>But the result I always get is "No Data found" although there IS an image file. Am I doing something wrong passing it as a POST parameter?</p>