curl_mime_init(3)

✨ curl_mime_init β€” create a mime handle ✨

okay so bestie, this one's from the libcurl gang β€” the Library Functions Manual girlies πŸ’… β€” and it's literally the birth certificate for a mime handle. baby's first mime structure, fr fr.


🌸 SYNOPSIS 🌸

#include <curl/curl.h>

curl_mime *curl_mime_init(CURL *easy_handle);

πŸ’– DESCRIPTION πŸ’–

curl_mime_init(3) creates a handle to a brand new, squeaky-clean, empty mime structure. it's giving blank canvas, main character energy 🎨✨

so what do you even do with it? lowkey you fill it up afterwards using the mime API (obsessed), and then you attach it to some easy handle with the CURLOPT_MIMEPOST(3) option inside a curl_easy_setopt(3) call β€” or, plot twist, you can add it as a multipart inside another mime handle's part using curl_mime_subparts(3). nesting? we love to see it πŸͺ†

easy_handle is used for part separator randomization and error reporting. and since 7.87.0, it does not need to be the final target handle β€” so it's flexible like that, no cap πŸ’β€β™€οΈ

ngl, using a mime handle is the recommended way to post an HTTP form, to format and send a multi-part email with SMTP, or to upload such an email to an IMAP server. all the icons do it. periodt πŸ‘‘

πŸ¦‹ PROTOCOLS πŸ¦‹

this functionality affects http, imap and smtp 🌈


πŸŽ€ EXAMPLE πŸŽ€

like, here's a whole entire vibe β€” building an HTTP form with one field and yeeting it into the world:

int main(void)
{
  CURL *easy = curl_easy_init();
  curl_mime *mime;
  curl_mimepart *part;

  /* Build an HTTP form with a single field named "data", */
  mime = curl_mime_init(easy);
  part = curl_mime_addpart(mime);
  curl_mime_data(part, "This is the field data", CURL_ZERO_TERMINATED);
  curl_mime_name(part, "data");

  /* Post and send it. */
  curl_easy_setopt(easy, CURLOPT_MIMEPOST, mime);
  curl_easy_setopt(easy, CURLOPT_URL, "https://example.com");
  curl_easy_perform(easy);

  /* Clean-up. */
  curl_easy_cleanup(easy);
  curl_mime_free(mime);
}

see how she builds the form, posts it, and then cleans up after herself? that's called being a responsible icon πŸ§šπŸ’œ


⭐ AVAILABILITY ⭐

added in curl 7.56.0 β€” so she's been serving since way back, iykyk πŸ•°οΈ


πŸ”₯ RETURN VALUE πŸ”₯

a mime struct handle, or NULL upon failure 😭 (if you get NULL, something went wrong β€” that's the whole tea)


πŸ‘‘ SEE ALSO πŸ‘‘


and that's the whole page bestie!! sourced straight from libcurl, dated 2026-10-12, written by the libcurl girlies themselves 🫢 go forth and mime responsibly, mwah πŸ’‹πŸŒΈ

πŸ“¦ where this page comes from