我想通过http post将文件上传到IIS或Apache等Web服务器。 该文件大于1GB,所以我想异步上传它。 但代码无法工作,从未执行过。回调“readfunc”函数? 有什么不对或我该怎么办? 非常感谢!
size_t readfunc(void *ptr, size_t size, size_t nmemb, void *stream)
{
FILE *f = (FILE *)stream;
size_t n;
if (ferror(f))
return CURL_READFUNC_ABORT;
n = fread(ptr, size, nmemb, f) * size;
return n;
}
void curl_post_form()
{
curl_global_init(CURL_GLOBAL_ALL);
CURL* hCurl = curl_easy_init();
if (hCurl != NULL)
{
curl_httppost* pFormPost = NULL;
curl_httppost* pLastElem = NULL;
curl_formadd(&pFormPost, &pLastElem,
CURLFORM_COPYNAME, "ufile01",
CURLFORM_FILE, "D:\\123.iso",
CURLFORM_CONTENTTYPE, "application/octet-stream",
CURLFORM_END);
curl_easy_setopt(hCurl, CURLOPT_HTTPPOST, pFormPost);
curl_easy_setopt(hCurl, CURLOPT_URL,"http://192.168.138.1:8800/Record/");
/* I want to use my own read function */
curl_easy_setopt(curlhandle, CURLOPT_READFUNCTION, readfunc);
/* now specify which file to upload */
curl_easy_setopt(curlhandle, CURLOPT_READDATA, f);
curl_easy_setopt(hCurl, CURLOPT_VERBOSE, 1L);
CURLcode res = curl_easy_perform(hCurl);
if (res != CURLE_OK)
{
printf("Error");
}
curl_formfree(pFormPost);
curl_easy_cleanup(hCurl);
}
curl_global_cleanup();
}