cURL / Mailing Lists / curl-library / Single Mail

curl-library

Uploading problems

From: Pavel Rozenblioum <prozen_at_gmail.com>
Date: Wed, 9 Aug 2006 17:41:54 +0200

Hi,
I am trying to build an Oz binding to libcurl and I seem to have some
problems with upload. When libcurl is supposed to be trying to read a
file it simple does nothing without ever entering the read function.
Here are the relevant parts of my code which are mostly the same as
the example code for http put which works as it's supposed to:

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

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

  return retcode;
}
/***snip***/

else if(strcmp(option,"put")==0){
        curl_easy_setopt(curl_handle, CURLOPT_READFUNCTION, read_callback);
        curl_easy_setopt(curl_handle, CURLOPT_UPLOAD, 1);
        curl_easy_setopt(curl_handle,CURLOPT_PUT,1);
        char* file=OZ_atomToC(OZ_subtree(record,OZ_atom("put"))); //getting
the filename
        int hd = open(file, O_RDONLY) ;
        fstat(hd, &file_info);
        close(hd);
        putfile=fopen(file,"rb");
        if(putfile == NULL){
          curl_easy_cleanup(curl_handle);
          OZ_RETURN_INT(-1);
          }
        curl_easy_setopt(curl_handle, CURLOPT_READDATA, putfile);
        curl_easy_setopt(curl_handle, CURLOPT_INFILESIZE_LARGE, file_info.st_size);
}
/****snip***/

The file size gets set correctly and the request gets sent correctly,
but no reading happens. Did I miss something really obvious?
I am using libcurl version 7.13.1, I am working under OS X and my
C-code is compiled into a dynamic library if any of that matters. Oh,
and I have write callbacks(also borrowed from the examples page)
working fine.

Anyone got any clue regarding what I am doing wrong?
With Best Regards,
Pavel Rozenblioum
Received on 2006-08-09