curl / Mailing Lists / curl-users / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Libcurl: Is there a problem combining CURLOPT_POSTFIELDS with CURLOPT_MIMEPOST?

From: kent williams via curl-users <curl-users_at_cool.haxx.se>
Date: Tue, 5 Jan 2021 14:19:49 -0600

This is an interesting thing. I've been asked add posting mime files to
our usual post data.  But the two options seem to conflict.

    void do_post(char *url, char *postdata, char *imagefilename) {
          CURL *chand = curl_easy_init();
          const long
    protocols(CURLPROTO_FTPS|CURLPROTO_HTTP|CURLPROTO_HTTPS);
          curl_easy_setopt(chand, CURLOPT_PROTOCOLS,protocols);
          curl_easy_setopt(chand, CURLOPT_NOPROGRESS, 1L);
          curl_easy_setopt(chand, CURLOPT_ERRORBUFFER, errbuf);
          curl_easy_setopt(chand, CURLOPT_URL, url.chars());
          curl_easy_setopt(chand, CURLOPT_NOSIGNAL, 1);
          curl_easy_setopt(chand, CURLOPT_POSTFIELDS, postdata);
          curl_easy_setopt(chand, CURLOPT_POSTFIELDSIZE, postdata.length());
          // set the postdata
          curl_easy_setopt(chand, CURLOPT_POSTFIELDS, postdata); //
    name=value pairs with & separating
          curl_easy_setopt(chand, CURLOPT_POSTFIELDSIZE, strlen(postdata);
          // set the mime file upload
               curl_mime *mime1(nullptr);
               curl_mimepart *part1(nullptr);
           // create a mime handle
           mime1 = curl_mime_init(chand);
           // get the part for the file
           part1 = curl_mime_addpart(mime1);
           // assign filename to part
           curl_mime_filedata(part1, imagefilename);
           curl_mime_name(part1, "image");
           curl_easy_setopt(chand, CURLOPT_MIMEPOST, mime1);
           int curlfailed = curl_easy_perform(chand);
           curl_mime_free(mime1);
           return curlfailed;
    }

What seems to be happening is that if you use CURLOPT_MIMEPOST, the
CURLOPT_POSTFIELDS are forgotten.  You can do the former, or the latter
but not both.

Is there a way this can happen -- i.e. add a file (i.e. an image file,
with CURLOPT_MIMEPOST) along with POSTFIELDS?




-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2021-01-05