curl_mime_type(3)
π curl_mime_type(3) β like, the mime type setter bestie
okay so this is curl_mime_type(3), from the libcurl Library Functions Manual, and it's genuinely one of the most useful little functions ever β it sets a mime part's content type. that's it. that's the whole vibe. π
β¨ NAME β¨
curl_mime_type β set a mime part's content type. iconic behavior, no notes.
β¨ SYNOPSIS β¨
#include <curl/curl.h>
CURLcode curl_mime_type(curl_mimepart *part, const char *mimetype);
β¨ DESCRIPTION β¨
curl_mime_type(3) sets a mime part's content type. slay.
part is the part's handle you're assigning the content type to. that's your main character right there.
mimetype points to the null-terminated file mime type string β and yes, it may be set to NULL if you want to remove a previously attached mime type. poof, gone, no cap. π
the mime type string is copied into the part, so the associated storage may safely be released or reused after the call. literally free yourself from worrying about it π. setting a part's type multiple times is valid: only the value set by the last call is retained. last one wins, periodt.
when there's no mime type set and the protocol specifications need one, a default mime type gets determined by the context:
- if set as a custom header, use this value.
application/form-datafor an HTTP form post.- if a remote filename is set, the mime type is taken from the filename extension, or
application/octet-streamby default. - for a multipart part,
multipart/mixed. text/plainin other cases.
ok so those defaults are not our problem, they just happen. but knowing them is highkey useful, iykyk π¦
β¨ PROTOCOLS β¨
this functionality affects http, imap and smtp π
β¨ EXAMPLE β¨
like, here's the whole thing in action:
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);
/* get data from this file */
curl_mime_filedata(part, "image.png");
/* content-type for this part */
curl_mime_type(part, "image/png");
/* set name */
curl_mime_name(part, "image");
}
}
(it really does just end like that, the braces said what they said π)
β¨ AVAILABILITY β¨
added in curl 7.56.0 β a certified classic at this point π
β¨ RETURN VALUE β¨
this function returns a CURLcode indicating success or error.
CURLE_OK (0) means everything was OK. non-zero means an error occurred, see libcurl-errors(3). and 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 you get receipts, bestie π§
β¨ SEE ALSO β¨
curl_mime_addpart(3), curl_mime_data(3), curl_mime_name(3)
that's the whole page, and honestly? obsessed. this came to you from libcurl, dated 2026-10-12 β go forth and set those mime types, bestie, you're literally gonna slay ππ«Άβ¨
π¦ 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