curl_mime_filedata.3 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at https://curl.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" * SPDX-License-Identifier: curl
  22. .\" *
  23. .\" **************************************************************************
  24. .TH curl_mime_filedata 3 "22 August 2017" "libcurl" "libcurl"
  25. .SH NAME
  26. curl_mime_filedata - set a mime part's body data from a file contents
  27. .SH SYNOPSIS
  28. .nf
  29. #include <curl/curl.h>
  30. CURLcode curl_mime_filedata(curl_mimepart *part,
  31. const char *filename);
  32. .fi
  33. .SH DESCRIPTION
  34. \fIcurl_mime_filedata(3)\fP sets a mime part's body content from the named
  35. file's contents. This is an alternative to \fIcurl_mime_data(3)\fP for setting
  36. data to a mime part.
  37. \fIpart\fP is the part's to assign contents to.
  38. \fIfilename\fP points to the null-terminated file's path name. The pointer can
  39. be NULL to detach the previous part contents settings. Filename storage can
  40. be safely be reused after this call.
  41. As a side effect, the part's remote file name is set to the base name of the
  42. given \fIfilename\fP if it is a valid named file. This can be undone or
  43. overridden by a subsequent call to \fIcurl_mime_filename(3)\fP.
  44. The contents of the file is read during the file transfer in a streaming
  45. manner to allow huge files to get transferred without using much memory. It
  46. therefore requires that the file is kept intact during the entire request.
  47. If the file size cannot be determined before actually reading it (such as for
  48. a device or named pipe), the whole mime structure containing the part
  49. will be transferred as chunks by HTTP and rejected by IMAP.
  50. Setting a part's contents multiple times is valid: only the value set by the
  51. last call is retained.
  52. .SH EXAMPLE
  53. .nf
  54. curl_mime *mime;
  55. curl_mimepart *part;
  56. /* create a mime handle */
  57. mime = curl_mime_init(easy);
  58. /* add a part */
  59. part = curl_mime_addpart(mime);
  60. /* send data from this file */
  61. curl_mime_filedata(part, "image.png");
  62. /* set name */
  63. curl_mime_name(part, "data");
  64. .fi
  65. .SH AVAILABILITY
  66. As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
  67. .SH RETURN VALUE
  68. CURLE_OK or a CURL error code upon failure. CURLE_READ_ERROR is only an
  69. indication that the file is not yet readable: it can be safely ignored at
  70. this time, but the file must be made readable before the pertaining
  71. easy handle is performed.
  72. .SH "SEE ALSO"
  73. .BR curl_mime_addpart "(3),"
  74. .BR curl_mime_data "(3),"
  75. .BR curl_mime_filename "(3),"
  76. .BR curl_mime_name "(3)"