你能告诉我有什么写的三个选项吗
libcurl
我写了一个函数来使用这里上传文件:
long RequestUploadFile(CkString Url,CkStringArray* filename,CkStringArray* filepaths) {
CURL *curl;
CURLcode res;
char *url = (char*)Url.getString();
struct curl_httppost *formpost = NULL;
struct curl_httppost *lastptr = NULL;
struct curl_slist *headerlist = NULL;
static const char buf[] = "Expect:";
curl_global_init(CURL_GLOBAL_ALL);
for (int i = 0; i < filename->get_Length(); i++)
{
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, filename->getString(i),
CURLFORM_FILE, filepaths->getString(i),
CURLFORM_END);
}
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "upload_type",
CURLFORM_COPYCONTENTS, "files",
CURLFORM_END);
long http_code = 0;
curl = curl_easy_init();
headerlist = curl_slist_append(headerlist, buf);
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
curl_formfree(formpost);
curl_slist_free_all(headerlist);
}
Url.clear();
filename->Clear();
filepaths->Clear();
return http_code;
}
我在我的代码中使用了该函数,如下所示上传一个文件:
CkStringArray filenames;
CkStringArray filepaths;
filenames.Append("file");
filepaths.Append("C:\\tss.bmp");
RequestUploadFile(RequestUrl, &filenames, &filepaths);
tss.bmp有 4mb 大小(未上传)
hello.txt有 2-3 kb 大小(上传成功)
这是什么原因以及如何解决?