248 curl_global_init(CURL_GLOBAL_DEFAULT);
249 curl = curl_easy_init();
251 struct curl_slist *
headers = NULL;
258 std::string content_type =
"application/octet-stream";
263 curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
273 curl_easy_setopt(curl, CURLOPT_URL,
url.c_str());
274 std::string js_str = js.dump();
279 std::string
format =
"X-Crest-PayloadFormat: ";
280 if (
files.size() > 0)
282 curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST,
"POST");
284 content_type =
"application/form-data";
288 curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST,
"PUT");
293 headers = curl_slist_append(
headers,
"Content-Type: multipart/form-data");
296 #if LIBCURL_VERSION_MAJOR < 8
297 struct curl_httppost *formpost = NULL;
298 struct curl_httppost *lastptr = NULL;
299 curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME,
"tag", CURLFORM_COPYCONTENTS,
tag.c_str(), CURLFORM_END);
300 curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME,
"endtime", CURLFORM_COPYCONTENTS,
std::to_string(endtime).c_str(), CURLFORM_END);
303 curl_formadd(&formpost, &lastptr,
304 CURLFORM_COPYNAME,
"storeset",
305 CURLFORM_BUFFER,
"json_data",
306 CURLFORM_BUFFERPTR, js_str.c_str(),
307 CURLFORM_BUFFERLENGTH, js_str.size(),
308 CURLFORM_CONTENTTYPE, content_type.c_str(),
311 curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME,
"version", CURLFORM_COPYCONTENTS,
version.c_str(), CURLFORM_END);
312 curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME,
"objectType", CURLFORM_COPYCONTENTS,
objectType.c_str(), CURLFORM_END);
313 curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME,
"compressionType", CURLFORM_COPYCONTENTS, compressionType.c_str(), CURLFORM_END);
317 curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME,
"files", CURLFORM_FILE,
file.c_str(), CURLFORM_END);
319 curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
323 curl_mime *mime = curl_mime_init(curl);
325 curl_mimepart *
part = curl_mime_addpart(mime);
326 curl_mime_name(
part,
"tag");
327 curl_mime_data(
part,
tag.c_str(),
tag.size());
329 part = curl_mime_addpart(mime);
331 curl_mime_name(
part,
"endtime");
332 curl_mime_data(
part, endtime_s.c_str(), endtime_s.size());
334 part = curl_mime_addpart(mime);
335 curl_mime_name(
part,
"version");
338 part = curl_mime_addpart(mime);
339 curl_mime_name(
part,
"objectType");
342 part = curl_mime_addpart(mime);
343 curl_mime_name(
part,
"compressionType");
344 curl_mime_data(
part, compressionType.c_str(), compressionType.size());
346 part = curl_mime_addpart(mime);
347 curl_mime_name(
part,
"storeset");
348 curl_mime_type(
part, content_type.c_str());
349 curl_mime_data(
part, js.dump().c_str(), js.dump().size());
353 curl_mimepart *
part = curl_mime_addpart(mime);
354 curl_mime_name(
part,
"files");
355 curl_mime_filedata(
part,
file.c_str());
358 curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
360 curl_easy_setopt(curl, CURLOPT_HTTPHEADER,
headers);
363 curl_easy_setopt(curl, CURLOPT_WRITEDATA, &
response);
366 CURLcode
res = curl_easy_perform(curl);
370 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
371 const char *method_name =
"CrestRequest::uploadPayload";
374 curl_easy_cleanup(curl);
375 #if LIBCURL_VERSION_MAJOR < 8
376 curl_formfree(formpost);
378 curl_mime_free(mime);
381 curl_global_cleanup();
388 std::string mes =
"ERROR in CrestRequest::uploadPayload";
389 throw CrestException(mes +
" | CURL not init");