Hello, I am trying to do a multipart/form-data upload with cURL + json + custom headers and I am not sure how to do it properly. I want something equivalent to this cmdline command: curl -H 'Content-Type: multipart/form-data' -H 'x-custom-header: custom value' https://url_to_upload -F "file=@file_to_upload" -F "params=@params.json"
For simple POST requests, I am doing this and works: curl_slist_append(headers, "Content-type: application/json")curl_slist_append(headers, "x-custom-header: custom value")curl_easy_setopt(CURLOPT_HTTPHEADER, headers);curl_easy_setopt(CURLOPT_POSTFIELDS, json_str); I read https://curl.se/libcurl/c/postit2.html, but still not sure how to send the json and the headers for multipart upload. 1. For JSON should I use CURLOPT_POSTFIELDS or curl_mime_addpart/curl_mime_name/curl_mime_data?2. For headers should I use CURLOPT_HTTPHEADER or curl_mime_headers?3. Can I reuse a mime handle for multiple files? Is there any way to reset it, so I won't do curl_mime_init/curl_mime_free for each file? thank you
-- Unsubscribe: https://lists.haxx.se/listinfo/curl-library Etiquette: https://curl.se/mail/etiquette.html