GNURLOPT_UPLOAD(3)
π GNURLOPT_UPLOAD(3) π
okay bestie, welcome to the GNURLOPT_UPLOAD(3) page from the curl_easy_setopt options manual. This is the glow-up for enabling data upload. No cap, it's giving βsend a file, but make it libcurl.β
πΈ NAME πΈ
CURLOPT_UPLOAD - enable data upload. periodt.
β¨ SYNOPSIS β¨
#include <gnurl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_UPLOAD, long upload);
π¦ DESCRIPTION π¦
The long parameter upload set to 1 tells the library to prepare for and perform an upload. Slay. The CURLOPT_READDATA(3) and CURLOPT_INFILESIZE(3) or CURLOPT_INFILESIZE_LARGE(3) options are also interesting for uploads β bestie, they're part of the upload squad.
If the protocol is HTTP, uploading means using the PUT request unless you tell libcurl otherwise. iykyk.
Using PUT with HTTP 1.1 implies the use of a "Expect: 100-continue" header. You can disable this header with CURLOPT_HTTPHEADER(3) as usual. the way that's just a normal Tuesday for libcurl.
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 CURLOPT_HTTPHEADER(3). With HTTP 1.0 or without chunked transfer, you must specify the size. do not skip the size in those cases, fr fr.
π DEFAULT π
0, default is download. so if you do nothing, you're downloading, not uploading. iconic default behavior.
π PROTOCOLS π
Most. yes, literally just βMostβ β we respect a mysterious queen.
π₯ EXAMPLE π₯
CURL *curl = curl_easy_init();
if(curl) {
/* we want to use our own read function */
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
/* enable uploading */
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
/* 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);
/* 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've been told! */
curl_easy_perform(curl);
}
That's the whole example. Copy it, love it, run it.
β AVAILABILITY β
Always. always and forever, bestie.
π RETURN VALUE π
Returns CURLE_OK. a clean return, we love to see it.
π«Ά SEE ALSO π«Ά
Also the original SEE ALSO list has a trailing comma after CURLOPT_INFILESIZE_LARGE(3), so respect the comma π
.
β with love from the libcurl 7.37.0 manual, dated 17 Jun 2014 π
π¦ where this page comes from
- nixos 26.05: libgnurl 7.72.0
- nixpkgs unstable: libgnurl 7.72.0
- Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms