CURLOPT_UPLOAD.3 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at https://curl.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" * SPDX-License-Identifier: curl
  22. .\" *
  23. .\" **************************************************************************
  24. .\"
  25. .TH CURLOPT_UPLOAD 3 "17 Jun 2014" libcurl libcurl
  26. .SH NAME
  27. CURLOPT_UPLOAD \- data upload
  28. .SH SYNOPSIS
  29. .nf
  30. #include <curl/curl.h>
  31. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_UPLOAD, long upload);
  32. .fi
  33. .SH DESCRIPTION
  34. The long parameter \fIupload\fP set to 1 tells the library to prepare for and
  35. perform an upload. The \fICURLOPT_READDATA(3)\fP and
  36. \fICURLOPT_INFILESIZE(3)\fP or \fICURLOPT_INFILESIZE_LARGE(3)\fP options are
  37. also interesting for uploads. If the protocol is HTTP, uploading means using
  38. the PUT request unless you tell libcurl otherwise.
  39. Using PUT with HTTP 1.1 implies the use of a "Expect: 100-continue" header.
  40. You can disable this header with \fICURLOPT_HTTPHEADER(3)\fP as usual.
  41. If you use PUT to an HTTP 1.1 server, you can upload data without knowing the
  42. size before starting the transfer. The library enables this by adding a header
  43. "Transfer-Encoding: chunked". With HTTP 1.0 or if you prefer not to use chunked
  44. transfer, you must specify the size of the data with
  45. \fICURLOPT_INFILESIZE(3)\fP or \fICURLOPT_INFILESIZE_LARGE(3)\fP.
  46. .SH DEFAULT
  47. 0, default is download
  48. .SH PROTOCOLS
  49. Most
  50. .SH EXAMPLE
  51. .nf
  52. CURL *curl = curl_easy_init();
  53. if(curl) {
  54. /* we want to use our own read function */
  55. curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
  56. /* enable uploading */
  57. curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
  58. /* specify target */
  59. curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/dir/to/newfile");
  60. /* now specify which pointer to pass to our callback */
  61. curl_easy_setopt(curl, CURLOPT_READDATA, hd_src);
  62. /* Set the size of the file to upload */
  63. curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)fsize);
  64. /* Now run off and do what you have been told! */
  65. curl_easy_perform(curl);
  66. }
  67. .fi
  68. .SH AVAILABILITY
  69. Always
  70. .SH RETURN VALUE
  71. Returns CURLE_OK
  72. .SH "SEE ALSO"
  73. .BR CURLOPT_PUT "(3), " CURLOPT_READFUNCTION "(3), "
  74. .BR CURLOPT_INFILESIZE_LARGE "(3), "