xref: /curl/docs/libcurl/curl_mime_encoder.md (revision 5a488251)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: curl_mime_encoder
5Section: 3
6Source: libcurl
7See-also:
8  - curl_mime_addpart (3)
9  - curl_mime_headers (3)
10  - curl_mime_subparts (3)
11Protocol:
12  - HTTP
13  - IMAP
14  - SMTP
15Added-in: 7.56.0
16---
17
18# NAME
19
20curl_mime_encoder - set a mime part's encoder and content transfer encoding
21
22# SYNOPSIS
23
24~~~c
25#include <curl/curl.h>
26
27CURLcode curl_mime_encoder(curl_mimepart *part, const char *encoding);
28~~~
29
30# DESCRIPTION
31
32curl_mime_encoder() requests a mime part's content to be encoded before being
33transmitted.
34
35*part* is the part's handle to assign an encoder.
36*encoding* is a pointer to a null-terminated encoding scheme. It may be
37set to NULL to disable an encoder previously attached to the part. The encoding
38scheme storage may safely be reused after this function returns.
39
40Setting a part's encoder multiple times is valid: only the value set by the
41last call is retained.
42
43Upon multipart rendering, the part's content is encoded according to the
44pertaining scheme and a corresponding *"Content-Transfer-Encoding"* header
45is added to the part.
46
47Supported encoding schemes are:
48
49"*binary*": the data is left unchanged, the header is added.
50
51"*8bit*": header added, no data change.
52
53"*7bit*": the data is unchanged, but is each byte is checked
54to be a 7-bit value; if not, a read error occurs.
55
56"*base64*": Data is converted to base64 encoding, then split in
57CRLF-terminated lines of at most 76 characters.
58
59"*quoted-printable*": data is encoded in quoted printable lines of
60at most 76 characters. Since the resulting size of the final data cannot be
61determined prior to reading the original data, it is left as unknown, causing
62chunked transfer in HTTP. For the same reason, this encoder may not be used
63with IMAP. This encoder targets text data that is mostly ASCII and should
64not be used with other types of data.
65
66If the original data is already encoded in such a scheme, a custom
67*Content-Transfer-Encoding* header should be added with
68curl_mime_headers(3) instead of setting a part encoder.
69
70Encoding should not be applied to multiparts, thus the use of this function on
71a part with content set with curl_mime_subparts(3) is strongly
72discouraged.
73
74# %PROTOCOLS%
75
76# EXAMPLE
77
78~~~c
79int main(void)
80{
81  curl_mime *mime;
82  curl_mimepart *part;
83
84  CURL *curl = curl_easy_init();
85  if(curl) {
86    /* create a mime handle */
87    mime = curl_mime_init(curl);
88
89    /* add a part */
90    part = curl_mime_addpart(mime);
91
92    /* send a file */
93    curl_mime_filedata(part, "image.png");
94
95    /* encode file data in base64 for transfer */
96    curl_mime_encoder(part, "base64");
97  }
98}
99~~~
100
101# %AVAILABILITY%
102
103# RETURN VALUE
104
105CURLE_OK or a CURL error code upon failure.
106