Imported Upstream version 7.59.0
[platform/upstream/curl.git] / docs / libcurl / curl_mime_filedata.3
1 .\" **************************************************************************
2 .\" *                                  _   _ ____  _
3 .\" *  Project                     ___| | | |  _ \| |
4 .\" *                             / __| | | | |_) | |
5 .\" *                            | (__| |_| |  _ <| |___
6 .\" *                             \___|\___/|_| \_\_____|
7 .\" *
8 .\" * Copyright (C) 1998 - 2018, 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.haxx.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 .\" **************************************************************************
22 .TH curl_mime_filedata 3 "January 14, 2018" "libcurl 7.59.0" "libcurl Manual"
23
24 .SH NAME
25 curl_mime_filedata - set a mime part's body data from a file contents
26 .SH SYNOPSIS
27 .B #include <curl/curl.h>
28 .sp
29 .BI "CURLcode curl_mime_filedata(curl_mimepart * " part ,
30 .BI " const char * " filename ");"
31 .ad
32 .SH DESCRIPTION
33 \fIcurl_mime_filedata(3)\fP sets a mime part's body content from the named
34 file's contents. This is an alernative to \fIcurl_mime_data(3)\fP for setting
35 data to a mime part.
36
37 \fIpart\fP is the part's to assign contents to.
38
39 \fIfilename\fP points to the nul-terminated file's path name. The pointer can
40 be NULL to detach the previous part contents settings.  Filename storage can be
41 safely be reused after this call.
42
43 As a side effect, the part's remote file name is set to the base name of the
44 given \fIfilename\fP if it is a valid named file. This can be undone or
45 overridden by a subsequent call to \fIcurl_mime_filename(3)\fP.
46
47 The contents of the file is read during the file transfer in a streaming
48 manner to allow huge files to get transferred without using much memory. It
49 therefore requires that the file is kept intact during the entire request.
50
51 If the file size cannot be determined before actually reading it (such as for
52 a device or named pipe), the whole mime structure containing the part
53 will be transferred as chunks by HTTP and rejected by IMAP.
54
55 Setting a part's contents twice is valid: only the value set by the last call
56 is retained.
57 .SH AVAILABILITY
58 As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
59 .SH RETURN VALUE
60 CURLE_OK or a CURL error code upon failure. CURLE_READ_ERROR is only an
61 indication that the file is not yet readable: it can be safely ignored at
62 this time, but the file must be made readable before the pertaining
63 easy handle is performed.
64 .SH EXAMPLE
65 .nf
66  curl_mime *mime;
67  curl_mimepart *part;
68
69  /* create a mime handle */
70  mime = curl_mime_init(easy);
71
72  /* add a part */
73  part = curl_mime_addpart(mime);
74
75  /* send data from this file */
76  curl_mime_filedata(part, "image.png");
77
78  /* set name */
79  curl_mime_name(part, "data");
80 .fi
81 .SH "SEE ALSO"
82 .BR curl_mime_addpart "(3),"
83 .BR curl_mime_data "(3),"
84 .BR curl_mime_filename "(3),"
85 .BR curl_mime_name "(3)"