1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: curl_mime_type 5Section: 3 6Source: libcurl 7See-also: 8 - curl_mime_addpart (3) 9 - curl_mime_data (3) 10 - curl_mime_name (3) 11Protocol: 12 - HTTP 13 - IMAP 14 - SMTP 15Added-in: 7.56.0 16--- 17 18# NAME 19 20curl_mime_type - set a mime part's content type 21 22# SYNOPSIS 23 24~~~c 25#include <curl/curl.h> 26 27CURLcode curl_mime_type(curl_mimepart *part, const char *mimetype); 28~~~ 29 30# DESCRIPTION 31 32curl_mime_type(3) sets a mime part's content type. 33 34*part* is the part's handle to assign the content type to. 35 36*mimetype* points to the null-terminated file mime type string; it may be 37set to NULL to remove a previously attached mime type. 38 39The mime type string is copied into the part, thus the associated storage may 40safely be released or reused after call. Setting a part's type multiple times 41is valid: only the value set by the last call is retained. 42 43In the absence of a mime type and if needed by the protocol specifications, 44a default mime type is determined by the context: 45 46- If set as a custom header, use this value. 47 48- application/form-data for an HTTP form post. 49 50- If a remote filename is set, the mime type is taken from the filename 51extension, or application/octet-stream by default. 52 53- For a multipart part, multipart/mixed. 54 55- text/plain in other cases. 56 57# %PROTOCOLS% 58 59# EXAMPLE 60 61~~~c 62int main(void) 63{ 64 curl_mime *mime; 65 curl_mimepart *part; 66 67 CURL *curl = curl_easy_init(); 68 if(curl) { 69 /* create a mime handle */ 70 mime = curl_mime_init(curl); 71 72 /* add a part */ 73 part = curl_mime_addpart(mime); 74 75 /* get data from this file */ 76 curl_mime_filedata(part, "image.png"); 77 78 /* content-type for this part */ 79 curl_mime_type(part, "image/png"); 80 81 /* set name */ 82 curl_mime_name(part, "image"); 83} 84} 85~~~ 86 87# %AVAILABILITY% 88 89# RETURN VALUE 90 91CURLE_OK or a CURL error code upon failure. 92