From 15cd35f67fa76f6d043bdf8e53b64ebb56339d2a Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 26 May 2004 09:00:03 +0000 Subject: added example that makes an upload to a file:// url --- docs/examples/fileupload.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 docs/examples/fileupload.c (limited to 'docs/examples/fileupload.c') diff --git a/docs/examples/fileupload.c b/docs/examples/fileupload.c new file mode 100644 index 000000000..315c2a1b1 --- /dev/null +++ b/docs/examples/fileupload.c @@ -0,0 +1,65 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +#include +#include +#include +#include + +int main(void) +{ + CURL *curl; + CURLcode res; + curl_off_t size; + struct stat file_info; + double speed_upload, total_time; + FILE *fd; + + fd = fopen("debugit", "r"); /* open file to upload */ + if(!fd) { + + return 1; /* can't continue */ + } + + stat("debugit", &file_info); /* to get the file size */ + + curl = curl_easy_init(); + if(curl) { + /* upload to this place */ + curl_easy_setopt(curl, CURLOPT_URL, + "file:///home/dast/src/curl/debug/new"); + + /* tell it to "upload" to the URL */ + curl_easy_setopt(curl, CURLOPT_UPLOAD, 1); + + /* set where to read from (on Windows you need to use READFUNCTION too) */ + curl_easy_setopt(curl, CURLOPT_READDATA, fd); + + /* and give the size of the upload (optional) */ + curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, + (curl_off_t)file_info.st_size); + + /* enable verbose for easier tracing */ + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); + + res = curl_easy_perform(curl); + + /* now extract transfer info */ + curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &speed_upload); + curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total_time); + + fprintf(stderr, "Speed: %.3f bytes/sec during %.3f seconds\n", + speed_upload, total_time); + + /* always cleanup */ + curl_easy_cleanup(curl); + } + return 0; +} -- cgit v1.2.1 From 0bfa601a9f074f56eabfe71dda265f3f594dae84 Mon Sep 17 00:00:00 2001 From: Gisle Vanem Date: Sat, 16 Oct 2004 13:17:15 +0000 Subject: Open "debugit" in binary mode ("rb"). --- docs/examples/fileupload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples/fileupload.c') diff --git a/docs/examples/fileupload.c b/docs/examples/fileupload.c index 315c2a1b1..455cb0ecf 100644 --- a/docs/examples/fileupload.c +++ b/docs/examples/fileupload.c @@ -22,7 +22,7 @@ int main(void) double speed_upload, total_time; FILE *fd; - fd = fopen("debugit", "r"); /* open file to upload */ + fd = fopen("debugit", "rb"); /* open file to upload */ if(!fd) { return 1; /* can't continue */ -- cgit v1.2.1 From 49ce3e5160a9576e797bf87cef012b09d1c54ecb Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Thu, 12 Jul 2007 21:11:10 +0000 Subject: Fixed some compile warnings and errors and improved portability in the examples. Removed ftp3rdparty.c since libcurl doesn't support 3rd party FTP transfers any longer. --- docs/examples/fileupload.c | 1 - 1 file changed, 1 deletion(-) (limited to 'docs/examples/fileupload.c') diff --git a/docs/examples/fileupload.c b/docs/examples/fileupload.c index 455cb0ecf..0f6e69d20 100644 --- a/docs/examples/fileupload.c +++ b/docs/examples/fileupload.c @@ -17,7 +17,6 @@ int main(void) { CURL *curl; CURLcode res; - curl_off_t size; struct stat file_info; double speed_upload, total_time; FILE *fd; -- cgit v1.2.1 From e664cd5826d43930fcc5b5dbaedbec94af33184b Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Thu, 22 May 2008 21:20:07 +0000 Subject: Fixed a surprising number of example programs that were passing int arguments to curl_easy_setopt instead of long. --- docs/examples/fileupload.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/examples/fileupload.c') diff --git a/docs/examples/fileupload.c b/docs/examples/fileupload.c index 0f6e69d20..cb88ef687 100644 --- a/docs/examples/fileupload.c +++ b/docs/examples/fileupload.c @@ -36,7 +36,7 @@ int main(void) "file:///home/dast/src/curl/debug/new"); /* tell it to "upload" to the URL */ - curl_easy_setopt(curl, CURLOPT_UPLOAD, 1); + curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); /* set where to read from (on Windows you need to use READFUNCTION too) */ curl_easy_setopt(curl, CURLOPT_READDATA, fd); @@ -46,7 +46,7 @@ int main(void) (curl_off_t)file_info.st_size); /* enable verbose for easier tracing */ - curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); res = curl_easy_perform(curl); -- cgit v1.2.1 From 152cf6325d3b1b0383d9c36fab9243005e4ea456 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Wed, 10 Sep 2008 07:11:45 +0000 Subject: Checked in some grammatical and minor other fixes in the documentation and examples that I found in the FreeBSD ports system. --- docs/examples/fileupload.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'docs/examples/fileupload.c') diff --git a/docs/examples/fileupload.c b/docs/examples/fileupload.c index cb88ef687..6ed523c36 100644 --- a/docs/examples/fileupload.c +++ b/docs/examples/fileupload.c @@ -27,7 +27,11 @@ int main(void) return 1; /* can't continue */ } - stat("debugit", &file_info); /* to get the file size */ + /* to get the file size */ + if(fstat(fileno(fd), &file_info) != 0) { + + return 1; /* can't continue */ + } curl = curl_easy_init(); if(curl) { -- cgit v1.2.1 From 2309b4e330b96bc2e1f8e36b6184015e59544037 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 24 Mar 2010 11:02:54 +0100 Subject: remove the CVSish $Id$ lines --- docs/examples/fileupload.c | 1 - 1 file changed, 1 deletion(-) (limited to 'docs/examples/fileupload.c') diff --git a/docs/examples/fileupload.c b/docs/examples/fileupload.c index 6ed523c36..cdec75137 100644 --- a/docs/examples/fileupload.c +++ b/docs/examples/fileupload.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ */ #include -- cgit v1.2.1 From 1aeb635cdd296c16acb375a4a83a78f13166ccab Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 10 Mar 2011 11:48:02 +0100 Subject: sources: update source headers All C and H files now (should) feature the proper project curl source code header, which includes basic info, a copyright statement and some basic disclaimers. --- docs/examples/fileupload.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'docs/examples/fileupload.c') diff --git a/docs/examples/fileupload.c b/docs/examples/fileupload.c index cdec75137..756367b6b 100644 --- a/docs/examples/fileupload.c +++ b/docs/examples/fileupload.c @@ -1,12 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ - + * Copyright (C) 1998 - 2011, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ #include #include #include -- cgit v1.2.1 From a3dbbcfd2ac7ab8f597e26e76935726279d3fa0c Mon Sep 17 00:00:00 2001 From: Guenter Knauf Date: Wed, 4 Jul 2012 17:03:52 +0200 Subject: Added error checking for samples. --- docs/examples/fileupload.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'docs/examples/fileupload.c') diff --git a/docs/examples/fileupload.c b/docs/examples/fileupload.c index 756367b6b..665eca0af 100644 --- a/docs/examples/fileupload.c +++ b/docs/examples/fileupload.c @@ -64,14 +64,21 @@ int main(void) curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); res = curl_easy_perform(curl); + /* Check for errors */ + if(res != CURLE_OK) { + fprintf(stderr, "curl_easy_perform() failed: %s\n", + curl_easy_strerror(res)); - /* now extract transfer info */ - curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &speed_upload); - curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total_time); + } + else { + /* now extract transfer info */ + curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &speed_upload); + curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total_time); - fprintf(stderr, "Speed: %.3f bytes/sec during %.3f seconds\n", - speed_upload, total_time); + fprintf(stderr, "Speed: %.3f bytes/sec during %.3f seconds\n", + speed_upload, total_time); + } /* always cleanup */ curl_easy_cleanup(curl); } -- cgit v1.2.1