uploading large file using libcurl c++

788 Views Asked by At

can you tell me what is there written three options

I wrote a function to upload files using libcurl here:

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;
}

I used that function in my code like the following to upload one file:

CkStringArray filenames;
CkStringArray filepaths;

filenames.Append("file");
filepaths.Append("C:\\tss.bmp");

RequestUploadFile(RequestUrl, &filenames, &filepaths);

tss.bmp has 4mb size (not uploaded)

hello.txt has 2-3 kb size (uploaded successfully)

What's the reason for that and how can it be resolved?

0

There are 0 best solutions below