79637486

Date: 2025-05-25 08:16:09
Score: 1
Natty:
Report link

If you're trying to upload a file with curlpp, the PostFields approach does not work. Instead you could use curlpp::FormParts. This has the file attachment option. So instead of,

    std::string POSTrequest = "[email protected]";
    
    request.setOpt(new curlpp::options::PostFields(POSTrequest));
    
    request.setOpt(new curlpp::options::PostFieldSize(POSTrequest.length()));
    request.setOpt(new curlpp::options::WriteStream(&std::cout));

You would write the following,

    std::string filename = "test.txt";

    curlpp::Forms formParts;
    formParts.push_back(new curlpp::FormParts::File("file", filename));
    request.setOpt(new curlpp::Options::HttpPost(formParts));

For more information you should check out this StackOverflow post. This approach is based on that post.

Furthermore, you could also look at the official curlpp forms example, although it doesn't demonstrate file uploading specifically.

Reasons:
  • Blacklisted phrase (1): StackOverflow
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Can Baykara