libcURL POST multipart upload (with buffered image) returning HTTP 400
<p>I'm sending a POST multipart to the Cloudinary API to upload an image I've captured and buffered using openCV. Cloudinary is giving me a HTTP 400. I've tested uploading the image with the chrome app <code>PostMan</code> and that works, so there must be an error in my POST request or something wrong about how I'm buffering my data.</p>

<p>Heres how they describe calls to the API:
<a href="http://cloudinary.com/documentation/upload_images#uploading_with_a_direct_call_to_the_api" rel="nofollow">http://cloudinary.com/documentation/upload_images#uploading_with_a_direct_call_to_the_api</a></p>

<p>I've been at this for days and any help would be greatly appreciated. Once this is figured out I will be submitting this code to Cloudinary so other users fiddling with C/C++ can easily upload to their platform without the pain I've gone through.</p>

<pre><code>//Clone frame and encode into buffer as JPEG
cv::Mat hand_roi = frame.clone();
std::vector&lt;unsigned char&gt; imgBuffer; 
imencode(".jpg", hand_roi, imgBuffer);

//Buffer to String with pointer/length
std::string imgStrBuff = std::string(imgBuffer.begin(), imgBuffer.end());
char *imgBuffPtr = (char *)&amp;imgStrBuff;
long imgBuffLength = static_cast&lt;long&gt;(imgStrBuff.size());

//Unix time in (s)
std::time_t t = std::time(0);
std::string unixTime = std::to_string(t);

//API_Secret:
std::string APISecret = "XXXXXXXXXXXXXXXXXXXXX";

//Create SHA1 signature required by cloudinary
std::string hashString = "timestamp=" + unixTime + APISecret;
std::string authSig = sha1(hashString);

//POST URL
std::string url = "https://api.cloudinary.com/v1_1/xxxxxxxxxxx/image/upload";

/*-----CURL SETUP-----*/
//Set headers as null
struct curl_slist *headers = NULL;
struct curl_httppost *formpost = NULL;
struct curl_httppost *lastptr = NULL;

//Data type 
curl_slist_append(headers, "Content-Type: multipart/form-data");

curl_global_init(CURL_GLOBAL_ALL);

curl_formadd(&amp;formpost,
             &amp;lastptr,
             CURLFORM_COPYNAME, "api_key",
             CURLFORM_COPYCONTENTS, "xxxAPIKeyxxx",
             CURLFORM_END);

curl_formadd(&amp;formpost,
             &amp;lastptr,
             CURLFORM_COPYNAME, "timestamp",
             CURLFORM_COPYCONTENTS, unixT.c_str(),
             CURLFORM_END);

curl_formadd(&amp;formpost,
             &amp;lastptr,
             CURLFORM_COPYNAME, "signature",
             CURLFORM_COPYCONTENTS, authSig.c_str(),
             CURLFORM_END);

curl_formadd(&amp;formpost,
             &amp;lastptr,
             CURLFORM_COPYNAME, "file",
             CURLFORM_BUFFER, "random_img_name.jpg",
             CURLFORM_BUFFERPTR, imgBuffPtr,
             CURLFORM_BUFFERLENGTH, imgBuffLength,
             CURLFORM_END);

//init easy_curl
CURL* curl = curl_easy_init();

if(!curl)
    return false;

curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);

res = curl_easy_perform(curl);
</code></pre>

<p>I've read basically all the libcurl documentation and I just can't figure out why these requests are being rejected.</p>