cURL / Mailing Lists / curl-library / Single Mail

curl-library

File uploaded via libcurl DLL doesn't contain any data

From: Pravin Jade <pravin.jade_at_lionbridge.com>
Date: Thu, 20 Nov 2003 18:27:35 +0530

Hi list ,

 I want to upload a file to Apache 2.0.46 server with Tomcat 4.1.24 as
servlet container using libcurl DLL. I am using HTTP protocol for this and
Windows 2000 OS.
 This uploading of file works perfectly for curl.exe.

 But while using libcurl DLL ,uploaded file don't contain any data (size = 0
bytes).Here library function curl_easy_perform (curl) returns CURLCODE as
CURLE_OK.
 My libcurl program is as follows-

#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>

#include <curl/curl.h>

size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
{
        size_t retcode;

        printf ("\nInside read_callback\n");

        retcode = fread(ptr, size, nmemb, stream);

        printf( "*** We read %d bytes from file ***\n", retcode);

        return retcode;
}

int main(int argc, char **argv)
{
  CURL *curl;
  CURLcode res;
  FILE * hd_src ;
  int hd ;
  struct stat file_info;

  char *file;
  char *url;

  file= "D:\\Gnanavel\\ncs4ScHhoolportal\\cocobase\\lib\\javax_ejb.zip";

  url="http://localhost:8080/put/put.do";

  /* get the file size of the local file */
   hd = open(file, O_RDONLY) ;
   fstat(hd, &file_info);
   close(hd) ;

  hd_src = fopen(file, "rb");

  if (hd_src == NULL)
    printf ("Unable to open file");

  /* In windows, this will init the winsock stuff */
  curl_global_init(CURL_GLOBAL_ALL);

  /* get a curl handle */
  curl = curl_easy_init();

  if(curl) {

          /* we want to use our own read function */

        curl_easy_setopt(curl, CURLOPT_READDATA,hd_src);

        curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);

         /* enable uploading */

        curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ;

         /* HTTP PUT please */
        curl_easy_setopt(curl, CURLOPT_PUT, TRUE);

         /* specify target */
        curl_easy_setopt(curl,CURLOPT_URL, url);

        // Set values of cookies to be sent to ASP side.
        curl_easy_setopt(curl,CURLOPT_COOKIE
,"fileName=file123;uploadDir=D:\\Uploadedfile" );
              printf("After setting cookies");

        /* Now run off and do what you've been told! */

        printf("\n Before easy perform");
        res = curl_easy_perform(curl);

        printf("\n After easy perform \n ");

        printf("CURLCODE := %d \n",res);

        /* always cleanup */
        curl_easy_cleanup(curl);
  }
  fclose(hd_src); /* close the local file */
  printf("After closing local file ");
  curl_global_cleanup();
  return 0;
}
Please help me in this regard. Does my servlet accepting PUT request require
any modification for libcurl ? This servlet works for file uploaded using
cURL EXE.

Regards,

Pravin.

-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/
Received on 2003-11-20