quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

CURLOPT_PUT.md (2039B)


      1 ---
      2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
      3 SPDX-License-Identifier: curl
      4 Title: CURLOPT_PUT
      5 Section: 3
      6 Source: libcurl
      7 See-also:
      8   - CURLOPT_HTTPGET (3)
      9   - CURLOPT_MIMEPOST (3)
     10   - CURLOPT_POSTFIELDS (3)
     11   - CURLOPT_UPLOAD (3)
     12 Protocol:
     13   - HTTP
     14 Added-in: 7.1
     15 ---
     16 
     17 # NAME
     18 
     19 CURLOPT_PUT - make an HTTP PUT request
     20 
     21 # SYNOPSIS
     22 
     23 ~~~c
     24 #include <curl/curl.h>
     25 
     26 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PUT, long put);
     27 ~~~
     28 
     29 # DESCRIPTION
     30 
     31 A parameter set to 1 tells the library to use HTTP PUT to transfer data. The
     32 data should be set with CURLOPT_READDATA(3) and
     33 CURLOPT_INFILESIZE(3).
     34 
     35 This option is **deprecated** since version 7.12.1. Use CURLOPT_UPLOAD(3).
     36 
     37 # DEFAULT
     38 
     39 0, disabled
     40 
     41 # %PROTOCOLS%
     42 
     43 # EXAMPLE
     44 
     45 ~~~c
     46 static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
     47 {
     48   FILE *src = userdata;
     49   /* copy as much data as possible into the 'ptr' buffer, but no more than
     50      'size' * 'nmemb' bytes */
     51   size_t retcode = fread(ptr, size, nmemb, src);
     52 
     53   return retcode;
     54 }
     55 
     56 int main(void)
     57 {
     58   CURL *curl = curl_easy_init();
     59   if(curl) {
     60     FILE *src = fopen("local-file", "r");
     61     curl_off_t fsize = 123456; /* set this to the size of the input file */
     62 
     63     /* we want to use our own read function */
     64     curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb);
     65 
     66     /* enable PUT */
     67     curl_easy_setopt(curl, CURLOPT_PUT, 1L);
     68 
     69     /* specify target */
     70     curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/dir/to/newfile");
     71 
     72     /* now specify which pointer to pass to our callback */
     73     curl_easy_setopt(curl, CURLOPT_READDATA, src);
     74 
     75     /* Set the size of the file to upload */
     76     curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)fsize);
     77 
     78     /* Now run off and do what you have been told */
     79     curl_easy_perform(curl);
     80   }
     81 }
     82 ~~~
     83 
     84 # DEPRECATED
     85 
     86 Deprecated since 7.12.1.
     87 
     88 # %AVAILABILITY%
     89 
     90 # RETURN VALUE
     91 
     92 curl_easy_setopt(3) returns a CURLcode indicating success or error.
     93 
     94 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see
     95 libcurl-errors(3).