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
{
"image": "binaryfile",
"type": "file"
}
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:
ifstream imageToConvert;
imageToConvert.open("path to file", ios::binary);
ostringstream ostrm;
if (imageToConvert.is_open())
{
ostrm << 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));
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?