curl_mime_filedata.3 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. .\" generated by cd2nroff 0.1 from curl_mime_filedata.md
  2. .TH curl_mime_filedata 3 "2025-01-17" libcurl
  3. .SH NAME
  4. curl_mime_filedata \- set a mime part\(aqs body data from a file contents
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_mime_filedata(curl_mimepart *part,
  9. const char *filename);
  10. .fi
  11. .SH DESCRIPTION
  12. \fIcurl_mime_filedata(3)\fP sets a mime part\(aqs body content from the named
  13. file\(aqs contents. This is an alternative to \fIcurl_mime_data(3)\fP for setting
  14. data to a mime part.
  15. \fIpart\fP is the part\(aqs to assign contents to.
  16. \fIfilename\fP points to the null\-terminated file\(aqs path name. The pointer can
  17. be NULL to detach the previous part contents settings. Filename storage can
  18. be safely be reused after this call.
  19. As a side effect, the part\(aqs remote filename is set to the base name of the
  20. given \fIfilename\fP if it is a valid named file. This can be undone or
  21. overridden by a subsequent call to \fIcurl_mime_filename(3)\fP.
  22. The contents of the file is read during the file transfer in a streaming
  23. manner to allow huge files to get transferred without using much memory. It
  24. therefore requires that the file is kept intact during the entire request.
  25. If the file size cannot be determined before actually reading it (such as for
  26. a character device or named pipe), the whole mime structure containing the
  27. part is transferred using chunks by HTTP but is rejected by IMAP.
  28. Setting a part\(aqs contents multiple times is valid: only the value set by the
  29. last call is retained.
  30. .SH PROTOCOLS
  31. This functionality affects http, imap and smtp
  32. .SH EXAMPLE
  33. .nf
  34. int main(void)
  35. {
  36. curl_mime *mime;
  37. curl_mimepart *part;
  38. CURL *curl = curl_easy_init();
  39. if(curl) {
  40. /* create a mime handle */
  41. mime = curl_mime_init(curl);
  42. /* add a part */
  43. part = curl_mime_addpart(mime);
  44. /* send data from this file */
  45. curl_mime_filedata(part, "image.png");
  46. /* set name */
  47. curl_mime_name(part, "data");
  48. }
  49. }
  50. .fi
  51. .SH AVAILABILITY
  52. Added in curl 7.56.0
  53. .SH RETURN VALUE
  54. CURLE_OK or a CURL error code upon failure. CURLE_READ_ERROR is only an
  55. indication that the file is not yet readable: it can be safely ignored at
  56. this time, but the file must be made readable before the pertaining
  57. easy handle is performed.
  58. .SH SEE ALSO
  59. .BR curl_mime_addpart (3),
  60. .BR curl_mime_data (3),
  61. .BR curl_mime_filename (3),
  62. .BR curl_mime_name (3)