[c++] upload image to imageshack
- by cinek1lol
Hi.
I would like to send pictures via a program written in C + +
I wrote such a thing using curl.exe
WinExec("C:\\curl\\curl.exe -H Expect: -F \"fileupload=@C:\\curl\\ok.jpg\" -F \"xml=yes\" -# \"http://www.imageshack.us/index.php\" -o data.txt -A \"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1\" -e \"http://www.imageshack.us\"", NULL);
This only works that I would like to send pictures to a variable pre-loaded char (you know what I mean? first reads the pictures into a variable and then send that variable), because now I have to specify the path to the images on disk
I wanted to make this program was written in C + + using the curl library, and not the exe.
I found it such a program (which some have modified)
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
int main(int argc, char *argv[])
{
CURL *curl;
CURLcode res;
struct curl_httppost *formpost=NULL;
struct curl_httppost *lastptr=NULL;
struct curl_slist *headerlist=NULL;
static const char buf[] = "Expect:";
curl_global_init(CURL_GLOBAL_ALL);
/* Fill in the file upload field */
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "send",
CURLFORM_FILE, "nowy.jpg",
CURLFORM_END);
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "nowy.jpg",
CURLFORM_COPYCONTENTS, "nowy.jpg",
CURLFORM_END);
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "submit",
CURLFORM_COPYCONTENTS, "send",
CURLFORM_END);
curl = curl_easy_init();
headerlist = curl_slist_append(headerlist, buf);
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://www.imageshack.us/index.php");
if ( (argc == 2) && (!strcmp(argv[1], "xml=yes")) )
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
curl_formfree(formpost);
curl_slist_free_all (headerlist);
}
system("pause");
return 0;
}
I will be grateful for any help