curl_mime_data(3)

πŸ’… curl_mime_data β€” bestie, it's the curl_mime_data(3) page from the Library Functions Manual ✨

okay so real talk, this one is a little icon. it's a libcurl function (you know, the C library situation πŸŽ€) and it does exactly one job: it slaps some body data from your memory straight onto a mime part. that's it. that's the whole gig. queen behavior honestly πŸ‘‘


🌸 NAME 🌸

curl_mime_data β€” set a mime part's body data from memory. no cap, that's literally it πŸ’–


✨ SYNOPSIS ✨

#include <curl/curl.h>

CURLcode curl_mime_data(curl_mimepart *part, const char *data,
                        size_t datasize);

πŸ¦‹ DESCRIPTION πŸ¦‹

so curl_mime_data(3) sets a mime part's body content, and the content comes from memory data. very much "here's my bytes, go off" energy πŸ’…

Let's break the args down because we respect clarity in this house:

  • part is the mime part you're assigning contents to. it's the one you already made with curl_mime_addpart(3). don't skip that step bestie, you need the part to exist first 🫢
  • data points to the data, and this function copies it. so the storage is yours again the moment the call returns β€” reuse it freely, it's giving "no strings attached" ✨
  • datasize is the number of bytes that data points to. you can also set it to CURL_ZERO_TERMINATED to say "hey, data is a null-terminated character string" and let it figure out the length itself πŸŽ€

Setting a part's contents multiple times is totally valid β€” only the value from the last call is retained. last one wins, main character energy πŸ‘‘ and if you want to unassign a part's contents entirely, just set data to NULL. poof, gone, no notes πŸ’€

⚠️ real talk: setting large data is memory consuming. if your data is chonky, you might wanna consider curl_mime_data_cb(3) instead. it's the cooler option for big stuff, iykyk πŸ“

🌈 PROTOCOLS 🌈

This functionality affects http, imap and smtp. the trio. periodt πŸ’œ


πŸŽ€ EXAMPLE πŸŽ€

int main(void)
{
  curl_mime *mime;
  curl_mimepart *part;

  CURL *curl = curl_easy_init();
  if(curl) {
    /* create a mime handle */
    mime = curl_mime_init(curl);

    /* add a part */
    part = curl_mime_addpart(mime);

    /* add data to the part  */
    curl_mime_data(part, "raw contents to send", CURL_ZERO_TERMINATED);
  }
}

look at that flow 😭 init the handle, add a part, feed it data. three steps, zero drama. we love a clean pipeline 🌸


⭐ AVAILABILITY ⭐

Added in curl 7.56.0. so if you're on something older than that... bestie. upgrade. respectfully πŸ™ˆ


πŸ’– RETURN VALUE πŸ’–

This function returns a CURLcode indicating success or error β€” classic libcurl move.

  • CURLE_OK (0) means everything was OK. slay, we're so back πŸŽ‰
  • non-zero means an error occurred, and you should go check libcurl-errors(3) for the tea πŸ”₯

and lowkey important: if CURLOPT_ERRORBUFFER(3) was set with curl_easy_setopt(3), there can be an error message stored in the error buffer when non-zero is returned. so when it goes wrong you actually get lore πŸ’€πŸ“–


πŸ‘‘ SEE ALSO πŸ‘‘

the whole mime friend group, go say hi 🫢


k bye, this page was brought to you by libcurl, dated 2026-10-12, and its original title was curl_mime_data(3) β€” thanks for reading bestie, go set some mime data, you're gonna do amazing πŸŒˆπŸ’…βœ¨

πŸ“¦ where this page comes from