CURLOPT_MIMEPOST(3)

πŸ’… CURLOPT_MIMEPOST β€” send data from a mime structure

okay so bestie, this is a libcurl manpage, and honestly? it's a good one. it lives in the Library Functions Manual and it's about sending data from a mime structure. yes queen, forms. let's go. πŸŽ€


✨ SYNOPSIS ✨

#include <curl/curl.h>

curl_mime *mime;

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_MIMEPOST, mime);

🌸 DESCRIPTION 🌸

so here's the vibe: you pass in a mime handle that you already got from curl_mime_init(3). that's it. that's the whole assignment. 🫢

this setting is supported by the HTTP protocol, where it posts forms, and by the SMTP and IMAP protocols, where it provides the email data to send/upload. multi-talented icon behavior, honestly.

this option is the preferred way of posting an HTTP form β€” it's replacing and extending the CURLOPT_HTTPPOST(3) option. out with the old, in with the mime. πŸ‘‘

⚠️ okay important thing, no cap: when you set CURLOPT_MIMEPOST(3) to NULL, libcurl resets the request type for HTTP back to the default, which disables the POST. and typically? that means it gets reset to GET. so instead of doing that, you should set a desired request method explicitly. don't just yeet it to NULL and hope, bestie 😭

πŸ¦‹ PROTOCOLS πŸ¦‹

this functionality affects http, imap and smtp. three protocols, one slay. ✨


πŸ’– EXAMPLE πŸ’–

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    curl_mime *multipart = curl_mime_init(curl);
    if(multipart) {
      curl_mimepart *part = curl_mime_addpart(multipart);
      curl_mime_name(part, "name");
      curl_mime_data(part, "daniel", CURL_ZERO_TERMINATED);
      part = curl_mime_addpart(multipart);
      curl_mime_name(part, "project");
      curl_mime_data(part, "curl", CURL_ZERO_TERMINATED);
      part = curl_mime_addpart(multipart);
      curl_mime_name(part, "logotype-image");
      curl_mime_filedata(part, "curl.png");

      /* Set the form info */
      curl_easy_setopt(curl, CURLOPT_MIMEPOST, multipart);

      curl_easy_perform(curl); /* post away */
      curl_mime_free(multipart); /* free the post data */
    }
  }
}

like?? look at her go. adds parts, names them, drops in data and a file, sets the form info, posts away, then frees the post data. the full character arc in one main. πŸ”₯


⭐ AVAILABILITY ⭐

added in curl 7.56.0. vintage-ish but still iconic. 🧚


🌈 RETURN VALUE 🌈

this returns CURLE_OK. that's it. success only, we love a low-drama return. πŸ’œ


πŸ’€ SEE ALSO πŸ’€


okay that's the page!! mwah πŸ’‹ this little beauty is from libcurl, dated 2026-10-12, and it goes by CURLOPT_MIMEPOST(3) in case you need to find her again. go post something cute πŸ“βœ¨

πŸ“¦ where this page comes from