curl-library
CURLFORM_STREAM bug?
Date: Tue, 23 Jun 2009 16:00:37 +0400
Hi
I try to use CURLFORM_STREAM for form file upload.
Documentation states that "CURLFORM_STREAM Tells libcurl to use the
CURLOPT_READFUNCTION callback to get data. The parameter you pass to
CURLFORM_STREAM is the pointer passed on to the read callback's fourth
argument".
So, I pass a pointer as an argument for this option and expect to get that
pointer in 'stream' arg of ReadData function.
But that's not how it appears to work. 'stream' arg contains pointer to
'__iob' type variable.
If I add the following piece of code:
curl_easy_setopt(h, CURLOPT_READDATA, NULL);
then NULL is passed to ReadData (and not the expected pointer).
Please, fix.
Here is the full text of example:
#include "stdafx.h"
#include "curl/curl.h"
size_t ReadData(void *ptr, size_t size, size_t nmemb, void *stream)
{
return 0;
}
struct Data
{
int a;
};
int _tmain(int argc, _TCHAR* argv[])
{
CURL *h;
h = curl_easy_init();
Data * r = new Data();
struct curl_httppost* post = NULL;
struct curl_httppost* last = NULL;
curl_easy_setopt(h, CURLOPT_URL, "http://localhost");
curl_easy_setopt(h, CURLOPT_READFUNCTION, ReadData);
curl_formadd(&post, &last,
CURLFORM_COPYNAME, "myfile",
CURLFORM_FILENAME, "file.zip",
CURLFORM_STREAM, r,
CURLFORM_CONTENTSLENGTH, 1000,
CURLFORM_CONTENTTYPE, "application/octet-stream",
CURLFORM_END);
curl_easy_setopt(h, CURLOPT_HTTPPOST, post);
curl_easy_setopt(h, CURLOPT_POST, 1);
CURLcode res = curl_easy_perform(h);
return 0;
}
Regards
Anton
Received on 2009-06-23