Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7438491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:33:45+00:00 2026-05-29T10:33:45+00:00

Take a look at the following code static size_t reader(void *ptr, size_t size, size_t

  • 0

Take a look at the following code

static size_t reader(void *ptr, size_t size, size_t nmemb, FILE *stream) {
    size_t retcode = fread(ptr, size, nmemb, stream);
    cout << "*** We read " << retcode << " bytes from file" << endl;
    return retcode;
}

void upload() { //upload() is called from ouside
    FILE *pFile;
    pFile = fopen("map.txt" , "r");

    struct stat file_info;
    stat("map.txt", &file_info);
    size_t size = (size_t)file_info.st_size;
    uploadFile(pFile, size);
}

bool uploadFile(void* data, size_t datasize) {
    CURL *curl;
    CURLcode res;

    curl = curl_easy_init();
    if (curl) {
        char *post_params = ...;
        curl_easy_setopt(curl, CURLOPT_URL, url);
        curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_params);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long) strlen(post_params));
        curl_easy_setopt(curl, CURLOPT_READFUNCTION, reader);
        curl_easy_setopt(curl, CURLOPT_READDATA, data);
        curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) datasize);

        res = curl_easy_perform(curl);
        curl_easy_cleanup(curl);
    }
    return true;
}

When the code is executed, the following is outputed

*** We read 490 bytes from file
*** We read 0 bytes from file

after that the app does nothing (even not exiting).

Can someone point out at what’s wrong here?

Will be grateful for any help!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:33:46+00:00Added an answer on May 29, 2026 at 10:33 am

    There’s some serious confusions shown in this code. Let me try to explain:

    CURLOPT_UPLOAD – this will ask libcurl to PUT the file when the protocol of choice is HTTP

    CURLOPT_POSTFIELDS – tells libcurl to POST the data that is provided in the additional argument (which has the size set with CURLOPT_POSTFIELDSIZE)

    CURLOPT_READFUNCTION – provides libcurl an alternative way to get data than CURLOPT_POSTFIELDS to allow a POST that reads the data from a file. When using CURLOPT_UPLOAD this is the only way to provide data.

    So in the end the questions left for you are:

    • Do you want PUT or POST?

    • Do you want to provide the data as a string or do you want it provided with a callback?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please take a look at the following code: public static void main(String[] args) {
Take a look at this code: public class Test { public static void main(String...
Take a look that the following code snippet: A a = null try {
Take a look at the following. The question near the end of the code
Please take a look at following code: #include <stdio.h> #include <iostream> using namespace std;
take a look at the following code I attempted to write inside a constructor:
Take a look at the following code: Number.prototype.isIn = function () { for (var
Take a look at the following code: var o; (function (p) { p =
Please take a look at the following code: Public Sub Method(Of TEntity As EntityObject)(ByVal
Would someone please take a look at the following code fragments (all from one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.