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-data for an HTTP form post.
  • if a remote filename is set, the mime type is taken from the filename extension, or application/octet-stream by default.
  • for a multipart part, multipart/mixed.
  • text/plain in 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