1CURLOPT_UPLOAD(3) libcurl CURLOPT_UPLOAD(3)
2
3
4
6 CURLOPT_UPLOAD - data upload
7
9 #include <curl/curl.h>
10
11 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_UPLOAD, long upload);
12
14 The long parameter upload set to 1 tells the library to prepare for and
15 perform an upload. The CURLOPT_READDATA(3) and CURLOPT_INFILESIZE(3) or
16 CURLOPT_INFILESIZE_LARGE(3) options are also interesting for uploads.
17 If the protocol is HTTP, uploading means using the PUT request unless
18 you tell libcurl otherwise.
19
20 Using PUT with HTTP 1.1 implies the use of a "Expect: 100-continue"
21 header. You can disable this header with CURLOPT_HTTPHEADER(3) as
22 usual.
23
24 If you use PUT to an HTTP 1.1 server, you can upload data without know‐
25 ing the size before starting the transfer. The library enables this by
26 adding a header "Transfer-Encoding: chunked". With HTTP 1.0 or if you
27 prefer not to use chunked transfer, you must specify the size of the
28 data with CURLOPT_INFILESIZE(3) or CURLOPT_INFILESIZE_LARGE(3).
29
31 0, default is download
32
34 Most
35
37 CURL *curl = curl_easy_init();
38 if(curl) {
39 /* we want to use our own read function */
40 curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
41
42 /* enable uploading */
43 curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
44
45 /* specify target */
46 curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/dir/to/newfile");
47
48 /* now specify which pointer to pass to our callback */
49 curl_easy_setopt(curl, CURLOPT_READDATA, hd_src);
50
51 /* Set the size of the file to upload */
52 curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)fsize);
53
54 /* Now run off and do what you have been told! */
55 curl_easy_perform(curl);
56 }
57
59 Always
60
62 Returns CURLE_OK
63
65 CURLOPT_PUT(3), CURLOPT_READFUNCTION(3), CURLOPT_INFILESIZE_LARGE(3),
66
67
68
69ibcurl 8.2.1 June 11, 2023 CURLOPT_UPLOAD(3)