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.