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