How do I POST a file to libcurl?
Do you mean RFC 1867 (that is, what the browser sends when a user submits an HTML form containing an input field with type = "file")?
If this is the case, you might be interested in http://curl.haxx.se/libcurl/c/postit2.html
source to share
From the documentation here :
With the "simple" libcurl interface, you start a session and get a handle (often called a "simple handle") that you use to enter the convenience interface functions you use. Use
curl_easy_init
to get a handle.You continue to tweak all the parameters you want in the upcoming transfer, the most important of which is the URL itself (you cannot transfer anything without the specified URL, as you might have figured out yourself). You might also want to set up some callbacks that will be called from the library when data is available, etc.
curl_easy_setopt
used for all this.When everything is set up, you tell libcurl to transfer using
curl_easy_perform
. Then it will perform the whole operation and will not return until it is done (successfully or not).After the transfer is complete, you can set new parameters and perform another transfer, or if you are done, clear the session by calling
curl_easy_cleanup
. If you need persistent connections, you do not clear them immediately, but instead perform other operations and perform other transfers using the same simple descriptor.
So it looks like you need to call the following:
-
curl_easy_init
(initialize a curling session) -
curl_easy_setopt
(setting session parameters) -
curl_easy_perform
(perform curl) -
curl_easy_cleanup
(delete session)
Considering that these are C APIs, you shouldn't have a problem calling them in a C ++ source file.
source to share