xref: /curl/docs/libcurl/curl_mime_filename.md (revision 5a488251)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: curl_mime_filename
5Section: 3
6Source: libcurl
7See-also:
8  - curl_mime_addpart (3)
9  - curl_mime_data (3)
10  - curl_mime_filedata (3)
11Protocol:
12  - HTTP
13  - IMAP
14  - SMTP
15Added-in: 7.56.0
16---
17
18# NAME
19
20curl_mime_filename - set a mime part's remote filename
21
22# SYNOPSIS
23
24~~~c
25#include <curl/curl.h>
26
27CURLcode curl_mime_filename(curl_mimepart *part,
28                            const char *filename);
29~~~
30
31# DESCRIPTION
32
33curl_mime_filename(3) sets a mime part's remote filename. When remote
34filename is set, content data is processed as a file, whatever is the part's
35content source. A part's remote filename is transmitted to the server in the
36associated Content-Disposition generated header.
37
38*part* is the part's handle to assign the remote filename to.
39
40*filename* points to the null-terminated filename string; it may be set
41to NULL to remove a previously attached remote filename.
42
43The remote filename string is copied into the part, thus the associated
44storage may safely be released or reused after call. Setting a part's file
45name multiple times is valid: only the value set by the last call is retained.
46
47# %PROTOCOLS%
48
49# EXAMPLE
50
51~~~c
52
53static char imagebuf[]="imagedata";
54
55int main(void)
56{
57  curl_mime *mime;
58  curl_mimepart *part;
59
60  CURL *curl = curl_easy_init();
61  if(curl) {
62    /* create a mime handle */
63    mime = curl_mime_init(curl);
64
65    /* add a part */
66    part = curl_mime_addpart(mime);
67
68    /* send image data from memory */
69    curl_mime_data(part, imagebuf, sizeof(imagebuf));
70
71    /* set a file name to make it look like a file upload */
72    curl_mime_filename(part, "image.png");
73
74    /* set name */
75    curl_mime_name(part, "data");
76  }
77}
78~~~
79
80# %AVAILABILITY%
81
82# RETURN VALUE
83
84CURLE_OK or a CURL error code upon failure.
85