curl_mime_init.3 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. .\" generated by cd2nroff 0.1 from curl_mime_init.md
  2. .TH curl_mime_init 3 "2025-01-17" libcurl
  3. .SH NAME
  4. curl_mime_init \- create a mime handle
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. curl_mime *curl_mime_init(CURL *easy_handle);
  9. .fi
  10. .SH DESCRIPTION
  11. \fIcurl_mime_init(3)\fP creates a handle to a new empty mime structure.
  12. This mime structure can be subsequently filled using the mime API, then
  13. attached to some easy handle using option \fICURLOPT_MIMEPOST(3)\fP within
  14. a \fIcurl_easy_setopt(3)\fP call or added as a multipart in another mime
  15. handle\(aqs part using \fIcurl_mime_subparts(3)\fP.
  16. \fIeasy_handle\fP is used for part separator randomization and error
  17. reporting. Since 7.87.0, it does not need to be the final target handle.
  18. Using a mime handle is the recommended way to post an HTTP form, format and
  19. send a multi\-part email with SMTP or upload such an email to an IMAP server.
  20. .SH PROTOCOLS
  21. This functionality affects http, imap and smtp
  22. .SH EXAMPLE
  23. .nf
  24. int main(void)
  25. {
  26. CURL *easy = curl_easy_init();
  27. curl_mime *mime;
  28. curl_mimepart *part;
  29. /* Build an HTTP form with a single field named "data", */
  30. mime = curl_mime_init(easy);
  31. part = curl_mime_addpart(mime);
  32. curl_mime_data(part, "This is the field data", CURL_ZERO_TERMINATED);
  33. curl_mime_name(part, "data");
  34. /* Post and send it. */
  35. curl_easy_setopt(easy, CURLOPT_MIMEPOST, mime);
  36. curl_easy_setopt(easy, CURLOPT_URL, "https://example.com");
  37. curl_easy_perform(easy);
  38. /* Clean-up. */
  39. curl_easy_cleanup(easy);
  40. curl_mime_free(mime);
  41. }
  42. .fi
  43. .SH AVAILABILITY
  44. Added in curl 7.56.0
  45. .SH RETURN VALUE
  46. A mime struct handle, or NULL upon failure.
  47. .SH SEE ALSO
  48. .BR CURLOPT_MIMEPOST (3),
  49. .BR curl_mime_addpart (3),
  50. .BR curl_mime_free (3),
  51. .BR curl_mime_subparts (3)