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:
partis the mime part you're assigning contents to. it's the one you already made withcurl_mime_addpart(3). don't skip that step bestie, you need the part to exist first π«Άdatapoints 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" β¨datasizeis the number of bytes thatdatapoints to. you can also set it toCURL_ZERO_TERMINATEDto say "hey,datais 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
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms