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 9274545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:22:45+00:00 2026-06-18T16:22:45+00:00

I am trying to send a multipart MIME message with custom streaming (multiple binary

  • 0

I am trying to send a multipart MIME message with custom streaming (multiple binary files). To this end, I cannot get my CURLOPT_READFUNCTION callback to use a pointer set by CURLFORM_STREAM.

So far as I can tell, the CURLFORM_STREAM documentation automatically calls the CURLOPT_READFUNCTION pointer when it begins to stream data. This is not happening for me.

Here’s my current code sample (I’ve been trying different configurations with no success). CURLCODECHECK and CURLFORMCHECK are macros that throw exceptions on an error. streams is a vector of my own StreamData structs.

        CURLCODECHECK(curl_easy_setopt(m_Curl, CURLOPT_HTTPPOST, 1L));
        CURLCODECHECK(curl_easy_setopt(m_Curl, CURLOPT_READFUNCTION, ::StreamReadFunction));

        for (auto iter = streams.begin(); iter != streams.end(); ++iter)
        {
            std::string const & name = iter->first;
            auto streamData = iter->second;

            CURLFORMCHECK(curl_formadd(&m_Post, &last,
                CURLFORM_COPYNAME, name.c_str(),
                CURLFORM_FILENAME, streamData->fileName.c_str(),
                CURLFORM_CONTENTTYPE, streamData->mimeType.c_str(),
                CURLFORM_STREAM, (void *) streamData.get(),
                CURLFORM_CONTENTSLENGTH, streamData->size,
                CURLFORM_END));
        }

My ::StreamReadFunction does get called, but unless I call curl_easy_setopt() with CURLOPT_READDATA set, it gets passed a null pointer for the fourth (void * userdata) argument.

  • 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-06-18T16:22:46+00:00Added an answer on June 18, 2026 at 4:22 pm

    In short, CURLOPT_HTTPPOST is not a replacement for CURLOPT_POST. Both must be provided and CURLOPT_POST must be set first.

    I moved my curl_formadd() call to the top of the function, and followed it with:

    CURLCODECHECK(curl_easy_setopt(m_Curl, CURLOPT_POST, 1L));
    CURLCODECHECK(curl_easy_setopt(m_Curl, CURLOPT_POSTFIELDSIZE, fieldSize));
    CURLCODECHECK(curl_easy_setopt(m_Curl, CURLOPT_READFUNCTION, ::StreamReadFunction));
    CURLCODECHECK(curl_easy_setopt(m_Curl, CURLOPT_HTTPPOST, m_Post));
    CURLCODECHECK(curl_easy_setopt(m_Curl, CURLOPT_VERBOSE, 1L));
    CURLCODECHECK(curl_easy_setopt(m_Curl, CURLOPT_HEADER, 1L));
    

    This then properly called my ::StreamReadFunction with my stream pointer.

    Note that CURLOPT_POST must be set before CURLOPT_HTTPPOST for the stream callback to use the proper pointer (placing CURLOPT_POST later will cause a null pointer to be passed in).

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

Sidebar

Related Questions

I'm trying to send a multipart/alternative MIME e-mail via PHP script ... all works
I am trying to send a gzip ed multipart POST to a Tomcat server
I`m trying to send simple html page with form data to user with GET,
I have been trying to get php to send a email with a attached
I'm trying to a upload file (or multiple files) to my servlet, which is
I'm trying to send emails out using MIME::Lite with authentication. Here's the code snippet
I am trying to send custom POST variables with each uploaded file. I have
I'm trying to send out a Plain/HTML multipart email out and I'm currently using
I'm trying to send a encrypted mail with JavaMail Library and BouncyCastle Library: This
I'm trying to send an HTML message while using SMTP authentication to Gmail in

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.