xref: /aosp_15_r20/external/curl/docs/libcurl/curl_mime_filedata.md (revision 6236dae45794135f37c4eb022389c904c8b0090d)
1*6236dae4SAndroid Build Coastguard Worker---
2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al.
3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl
4*6236dae4SAndroid Build Coastguard WorkerTitle: curl_mime_filedata
5*6236dae4SAndroid Build Coastguard WorkerSection: 3
6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl
7*6236dae4SAndroid Build Coastguard WorkerSee-also:
8*6236dae4SAndroid Build Coastguard Worker  - curl_mime_addpart (3)
9*6236dae4SAndroid Build Coastguard Worker  - curl_mime_data (3)
10*6236dae4SAndroid Build Coastguard Worker  - curl_mime_filename (3)
11*6236dae4SAndroid Build Coastguard Worker  - curl_mime_name (3)
12*6236dae4SAndroid Build Coastguard WorkerProtocol:
13*6236dae4SAndroid Build Coastguard Worker  - HTTP
14*6236dae4SAndroid Build Coastguard Worker  - IMAP
15*6236dae4SAndroid Build Coastguard Worker  - SMTP
16*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.56.0
17*6236dae4SAndroid Build Coastguard Worker---
18*6236dae4SAndroid Build Coastguard Worker
19*6236dae4SAndroid Build Coastguard Worker# NAME
20*6236dae4SAndroid Build Coastguard Worker
21*6236dae4SAndroid Build Coastguard Workercurl_mime_filedata - set a mime part's body data from a file contents
22*6236dae4SAndroid Build Coastguard Worker
23*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS
24*6236dae4SAndroid Build Coastguard Worker
25*6236dae4SAndroid Build Coastguard Worker~~~c
26*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h>
27*6236dae4SAndroid Build Coastguard Worker
28*6236dae4SAndroid Build Coastguard WorkerCURLcode curl_mime_filedata(curl_mimepart *part,
29*6236dae4SAndroid Build Coastguard Worker                            const char *filename);
30*6236dae4SAndroid Build Coastguard Worker~~~
31*6236dae4SAndroid Build Coastguard Worker
32*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION
33*6236dae4SAndroid Build Coastguard Worker
34*6236dae4SAndroid Build Coastguard Workercurl_mime_filedata(3) sets a mime part's body content from the named
35*6236dae4SAndroid Build Coastguard Workerfile's contents. This is an alternative to curl_mime_data(3) for setting
36*6236dae4SAndroid Build Coastguard Workerdata to a mime part.
37*6236dae4SAndroid Build Coastguard Worker
38*6236dae4SAndroid Build Coastguard Worker*part* is the part's to assign contents to.
39*6236dae4SAndroid Build Coastguard Worker
40*6236dae4SAndroid Build Coastguard Worker*filename* points to the null-terminated file's path name. The pointer can
41*6236dae4SAndroid Build Coastguard Workerbe NULL to detach the previous part contents settings. Filename storage can
42*6236dae4SAndroid Build Coastguard Workerbe safely be reused after this call.
43*6236dae4SAndroid Build Coastguard Worker
44*6236dae4SAndroid Build Coastguard WorkerAs a side effect, the part's remote filename is set to the base name of the
45*6236dae4SAndroid Build Coastguard Workergiven *filename* if it is a valid named file. This can be undone or
46*6236dae4SAndroid Build Coastguard Workeroverridden by a subsequent call to curl_mime_filename(3).
47*6236dae4SAndroid Build Coastguard Worker
48*6236dae4SAndroid Build Coastguard WorkerThe contents of the file is read during the file transfer in a streaming
49*6236dae4SAndroid Build Coastguard Workermanner to allow huge files to get transferred without using much memory. It
50*6236dae4SAndroid Build Coastguard Workertherefore requires that the file is kept intact during the entire request.
51*6236dae4SAndroid Build Coastguard Worker
52*6236dae4SAndroid Build Coastguard WorkerIf the file size cannot be determined before actually reading it (such as for
53*6236dae4SAndroid Build Coastguard Workera character device or named pipe), the whole mime structure containing the
54*6236dae4SAndroid Build Coastguard Workerpart is transferred using chunks by HTTP but is rejected by IMAP.
55*6236dae4SAndroid Build Coastguard Worker
56*6236dae4SAndroid Build Coastguard WorkerSetting a part's contents multiple times is valid: only the value set by the
57*6236dae4SAndroid Build Coastguard Workerlast call is retained.
58*6236dae4SAndroid Build Coastguard Worker
59*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS%
60*6236dae4SAndroid Build Coastguard Worker
61*6236dae4SAndroid Build Coastguard Worker# EXAMPLE
62*6236dae4SAndroid Build Coastguard Worker
63*6236dae4SAndroid Build Coastguard Worker~~~c
64*6236dae4SAndroid Build Coastguard Workerint main(void)
65*6236dae4SAndroid Build Coastguard Worker{
66*6236dae4SAndroid Build Coastguard Worker  curl_mime *mime;
67*6236dae4SAndroid Build Coastguard Worker  curl_mimepart *part;
68*6236dae4SAndroid Build Coastguard Worker
69*6236dae4SAndroid Build Coastguard Worker  CURL *curl = curl_easy_init();
70*6236dae4SAndroid Build Coastguard Worker  if(curl) {
71*6236dae4SAndroid Build Coastguard Worker    /* create a mime handle */
72*6236dae4SAndroid Build Coastguard Worker    mime = curl_mime_init(curl);
73*6236dae4SAndroid Build Coastguard Worker
74*6236dae4SAndroid Build Coastguard Worker    /* add a part */
75*6236dae4SAndroid Build Coastguard Worker    part = curl_mime_addpart(mime);
76*6236dae4SAndroid Build Coastguard Worker
77*6236dae4SAndroid Build Coastguard Worker    /* send data from this file */
78*6236dae4SAndroid Build Coastguard Worker    curl_mime_filedata(part, "image.png");
79*6236dae4SAndroid Build Coastguard Worker
80*6236dae4SAndroid Build Coastguard Worker    /* set name */
81*6236dae4SAndroid Build Coastguard Worker    curl_mime_name(part, "data");
82*6236dae4SAndroid Build Coastguard Worker  }
83*6236dae4SAndroid Build Coastguard Worker}
84*6236dae4SAndroid Build Coastguard Worker~~~
85*6236dae4SAndroid Build Coastguard Worker
86*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY%
87*6236dae4SAndroid Build Coastguard Worker
88*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE
89*6236dae4SAndroid Build Coastguard Worker
90*6236dae4SAndroid Build Coastguard WorkerCURLE_OK or a CURL error code upon failure. CURLE_READ_ERROR is only an
91*6236dae4SAndroid Build Coastguard Workerindication that the file is not yet readable: it can be safely ignored at
92*6236dae4SAndroid Build Coastguard Workerthis time, but the file must be made readable before the pertaining
93*6236dae4SAndroid Build Coastguard Workereasy handle is performed.
94