xref: /curl/docs/libcurl/curl_mime_data.md (revision 5a488251)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: curl_mime_data
5Section: 3
6Source: libcurl
7See-also:
8  - curl_mime_addpart (3)
9  - curl_mime_data_cb (3)
10  - curl_mime_name (3)
11  - curl_mime_type (3)
12Protocol:
13  - HTTP
14  - IMAP
15  - SMTP
16Added-in: 7.56.0
17---
18
19# NAME
20
21curl_mime_data - set a mime part's body data from memory
22
23# SYNOPSIS
24
25~~~c
26#include <curl/curl.h>
27
28CURLcode curl_mime_data(curl_mimepart *part, const char *data,
29                        size_t datasize);
30~~~
31
32# DESCRIPTION
33
34curl_mime_data(3) sets a mime part's body content from memory data.
35
36*part* is the mime part to assign contents to, created with
37curl_mime_addpart(3).
38
39*data* points to the data that gets copied by this function. The storage
40may safely be reused after the call.
41
42*datasize* is the number of bytes *data* points to. It can be set to
43*CURL_ZERO_TERMINATED* to indicate *data* is a null-terminated
44character string.
45
46Setting a part's contents multiple times is valid: only the value set by the
47last call is retained. It is possible to unassign part's contents by setting
48*data* to NULL.
49
50Setting large data is memory consuming: one might consider using
51curl_mime_data_cb(3) in such a case.
52
53# %PROTOCOLS%
54
55# EXAMPLE
56
57~~~c
58int main(void)
59{
60  curl_mime *mime;
61  curl_mimepart *part;
62
63  CURL *curl = curl_easy_init();
64  if(curl) {
65    /* create a mime handle */
66    mime = curl_mime_init(curl);
67
68    /* add a part */
69    part = curl_mime_addpart(mime);
70
71    /* add data to the part  */
72    curl_mime_data(part, "raw contents to send", CURL_ZERO_TERMINATED);
73  }
74}
75~~~
76
77# %AVAILABILITY%
78
79# RETURN VALUE
80
81CURLE_OK or a CURL error code upon failure.
82