title: Send image in http post via json object using cpprest
body: <p>I am using the library cpprest. I am trying to send an image file as a binary file to an endpoint. I need it to follow the json structure of</p>
  
  <pre><code>{
      "image": "binaryfile",
      "type": "file"
  }
  </code></pre>
  
  <p>However I don't know how to do that and only fine examples on receiving binary data. So this is what I have so far:</p>
  
  <pre><code>ifstream imageToConvert;
  
  imageToConvert.open("path to file", ios::binary);
  
  ostringstream ostrm;
  
  
  if (imageToConvert.is_open())
  {
      ostrm &lt;&lt; imageToConvert.rdbuf();
      imageToConvert.close();
  }
  imageToConvert.close();
  
  //build json string to convert
  string MY_JSON = ("{\"image\" : \"");
  MY_JSON += (ostrm.str());
  MY_JSON += ("\",\"type\" : \"file\"}");
  
  //set up json object
  json::value obj;
  obj.parse(utility::conversions::to_string_t(MY_JSON));
  </code></pre>
  
  <p>however this throws a memory fault exception. So my questions are, what is the best way to get this binary data from the file, and how do I correctly build my json object to send off in my post?</p>