summaryrefslogtreecommitdiff
path: root/docs/libcurl/opts/CURLOPT_UPLOAD.3
diff options
context:
space:
mode:
authorSeonah Moon <seonah1.moon@samsung.com>2024-01-02 20:07:54 +0900
committerSeonah Moon <seonah1.moon@samsung.com>2024-01-02 20:37:43 +0900
commitaf71747bfb8e0dfb8b2870e30d720ce10b839814 (patch)
treedfd86789c7a44fccf1847280213d4ff10e41cc06 /docs/libcurl/opts/CURLOPT_UPLOAD.3
parentb16a7a56e08377965863acf50afb7d91f32ba995 (diff)
downloadcurl-af71747bfb8e0dfb8b2870e30d720ce10b839814.tar.gz
curl-af71747bfb8e0dfb8b2870e30d720ce10b839814.tar.bz2
curl-af71747bfb8e0dfb8b2870e30d720ce10b839814.zip
Imported Upstream version 8.5.0upstream/8.5.0upstream
Change-Id: I8f77c680623836749aba616cecd0390fc34b0c3c
Diffstat (limited to 'docs/libcurl/opts/CURLOPT_UPLOAD.3')
-rw-r--r--docs/libcurl/opts/CURLOPT_UPLOAD.361
1 files changed, 39 insertions, 22 deletions
diff --git a/docs/libcurl/opts/CURLOPT_UPLOAD.3 b/docs/libcurl/opts/CURLOPT_UPLOAD.3
index 5c78f1f2c..c5704d6d6 100644
--- a/docs/libcurl/opts/CURLOPT_UPLOAD.3
+++ b/docs/libcurl/opts/CURLOPT_UPLOAD.3
@@ -5,7 +5,7 @@
.\" * | (__| |_| | _ <| |___
.\" * \___|\___/|_| \_\_____|
.\" *
-.\" * Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
+.\" * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
.\" *
.\" * This software is licensed as described in the file COPYING, which
.\" * you should have received as part of this distribution. The terms
@@ -22,7 +22,7 @@
.\" *
.\" **************************************************************************
.\"
-.TH CURLOPT_UPLOAD 3 "May 17, 2022" "libcurl 7.86.0" "curl_easy_setopt options"
+.TH CURLOPT_UPLOAD 3 "December 04, 2023" "ibcurl 8.5.0" libcurl
.SH NAME
CURLOPT_UPLOAD \- data upload
@@ -43,35 +43,51 @@ Using PUT with HTTP 1.1 implies the use of a "Expect: 100-continue" header.
You can disable this header with \fICURLOPT_HTTPHEADER(3)\fP as usual.
If you use PUT to an HTTP 1.1 server, you can upload data without knowing the
-size before starting the transfer if you use chunked encoding. You enable this
-by adding a header like "Transfer-Encoding: chunked" with
-\fICURLOPT_HTTPHEADER(3)\fP. With HTTP 1.0 or without chunked transfer, you
-must specify the size.
+size before starting the transfer. The library enables this by adding a header
+"Transfer-Encoding: chunked". With HTTP 1.0 or if you prefer not to use chunked
+transfer, you must specify the size of the data with
+\fICURLOPT_INFILESIZE(3)\fP or \fICURLOPT_INFILESIZE_LARGE(3)\fP.
.SH DEFAULT
0, default is download
.SH PROTOCOLS
Most
.SH EXAMPLE
.nf
-CURL *curl = curl_easy_init();
-if(curl) {
- /* we want to use our own read function */
- curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
+static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
+{
+ FILE *src = userdata;
+ /* copy as much data as possible into the 'ptr' buffer, but no more than
+ 'size' * 'nmemb' bytes! */
+ size_t retcode = fread(ptr, size, nmemb, src);
- /* enable uploading */
- curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
+ return retcode;
+}
+
+int main(void)
+{
+ CURL *curl = curl_easy_init();
+ if(curl) {
+ FILE *src = fopen("local-file", "r");
+ curl_off_t fsize; /* set this to the size of the input file */
+
+ /* we want to use our own read function */
+ curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb);
+
+ /* enable uploading */
+ curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
- /* specify target */
- curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/dir/to/newfile");
+ /* specify target */
+ curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/dir/to/newfile");
- /* now specify which pointer to pass to our callback */
- curl_easy_setopt(curl, CURLOPT_READDATA, hd_src);
+ /* now specify which pointer to pass to our callback */
+ curl_easy_setopt(curl, CURLOPT_READDATA, src);
- /* Set the size of the file to upload */
- curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)fsize);
+ /* Set the size of the file to upload */
+ curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)fsize);
- /* Now run off and do what you have been told! */
- curl_easy_perform(curl);
+ /* Now run off and do what you have been told! */
+ curl_easy_perform(curl);
+ }
}
.fi
.SH AVAILABILITY
@@ -79,5 +95,6 @@ Always
.SH RETURN VALUE
Returns CURLE_OK
.SH "SEE ALSO"
-.BR CURLOPT_PUT "(3), " CURLOPT_READFUNCTION "(3), "
-.BR CURLOPT_INFILESIZE_LARGE "(3), "
+.BR CURLOPT_PUT (3),
+.BR CURLOPT_READFUNCTION (3),
+.BR CURLOPT_INFILESIZE_LARGE (3)