curl_mime_filename(3)
π curl_mime_filename(3) β the glow-up
okay bestie, welcome to the curl_mime_filename(3) page β¨ this one lives in the Library Functions Manual section of libcurl (yes, the actual manual name, we're being official today π) and it's literally about giving your mime part a cute little remote filename so the server thinks it's a real file. no cap.
β¨ NAME β¨
curl_mime_filename β set a mime part's remote filename π¦
πΈ SYNOPSIS πΈ
#include <curl/curl.h>
CURLcode curl_mime_filename(curl_mimepart *part,
const char *filename);
π DESCRIPTION π
okay so curl_mime_filename(3) sets a mime part's remote filename. and here's the iconic part: once the remote filename is set, the content data gets processed as a file β whatever the part's content source happens to be. the way that works is that the part's remote filename gets transmitted to the server in the associated Content-Disposition generated header. slay. π
part is the part's handle β that's who you're assigning the remote filename to.
filename points to the null-terminated filename string π and plot twist: it may be set to NULL to remove a previously attached remote filename. clean slate, we love to see it.
the remote filename string gets copied into the part, so the associated storage may safely be released or reused after the call π«Ά (no spooky lingering pointers, we stan). and setting a part's file name multiple times is totally valid β only the value set by the last call is retained. last one wins, main character energy fr fr π
π₯ PROTOCOLS π₯
this functionality affects http, imap and smtp β¨
π EXAMPLE π
static char imagebuf[]="imagedata";
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);
/* send image data from memory */
curl_mime_data(part, imagebuf, sizeof(imagebuf));
/* set a file name to make it look like a file upload */
curl_mime_filename(part, "image.png");
/* set name */
curl_mime_name(part, "data");
}
}
look at her go π memory buffer in, but with a image.png filename it's giving file upload β the server will never know the difference π
β AVAILABILITY β
Added in curl 7.56.0 π± (yes she's been iconic for a while)
π 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 ngl, 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 check it, bestie.
π SEE ALSO π
mwah π that's the whole page β brought to you by libcurl, dated 2026-10-12, filed under curl_mime_filename(3). go forth and name your mime parts, queen π§
π¦ 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