gnurl_mime_type(3)

πŸ“¦ version 7.72.0, in nixos 26.05, nixpkgs unstable

πŸ’… gnurl_mime_type πŸ’…

okay so bestie, welcome to the libgnurl corner of the manual β€” this one's about gnurl_mime_type(3), and it's a lil' function that has ONE job and does it slayfully.


✨ NAME ✨

curl_mime_type β€” sets a mime part's content type πŸŽ€


✨ SYNOPSIS ✨

#include <gnurl/curl.h>

CURLcode curl_mime_type(curl_mimepart * part, const char * mimetype);

✨ DESCRIPTION ✨

So curl_mime_type(3) sets a mime part's content type. That's it. That's the whole vibe. πŸ¦‹

part is the part's handle β€” the one you're assigning the content type to, bestie. Like, the specific part you're dressing up.

mimetype points to the null-terminated file mime type string. And listen β€” it may be set to NULL to remove a previously attached mime type. So if you change your mind, no cap, you can just yeet it. πŸ’€

The mime type string is copied into the part, so the associated storage may safely be released or reused after the call. ngl that's the polite thing to do. Setting a part's type twice is totally valid: only the value set by the last call is retained. Last one wins, periodt. πŸ‘‘

In the absence of a mime type and if needed by the protocol specifications, a default mime type is determined by the context:

  • If set as a custom header, use this value.
  • application/form-data for an HTTP form post.
  • If a remote file name is set, the mime type is taken from the file name extension, or application/octet-stream by default.
  • For a multipart part, multipart/mixed.
  • text/plain in other cases.

so yeah, it's giving "the function has a fallback plan for every situation" energy. 🌸


✨ AVAILABILITY ✨

Works as long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0. ✨


✨ RETURN VALUE ✨

You get CURLE_OK if it ate, or a CURL error code upon failure. 😭


✨ EXAMPLE ✨

 curl_mime *mime;
 curl_mimepart *part;

 /* create a mime handle */
 mime = curl_mime_init(easy);

 /* 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");

look at that. main character code, honestly. πŸ”₯


✨ SEE ALSO ✨


and that's the whole page, bestie!! 🫢 this lil' writeup lives in the libcurl 7.56.0 era, dated 22 August 2017 β€” so go forth, set those mime types, and remember: only the last call is retained. iykyk πŸ’œπŸŽ€

πŸ“¦ where this page comes from