Hi all,

I'm trying to POST a file in a multipart message. The problem is that I need to 
pass two extra parameters with that file. And I want them to be accessible in 
POST parameters array. The question is whether is possible to add part to 
multipart message so that it'll be interpreted as POST parameter? Or am I 
wasting time?

Take a look at following code

                               headers = curl_slist_append(headers, 
"Content-Disposition: form-data");

                               //action=upload
                               curl_formadd(&formpost,
                                               &lastptr,
                                               CURLFORM_COPYNAME, "action",
                                               CURLFORM_COPYCONTENTS, "upload",
                                               CURLFORM_CONTENTTYPE, 
"Content-Type: multipart/form-data",
                                               CURLFORM_END);

                               curl_formadd(&formpost,
                                               &lastptr,
                                               CURLFORM_COPYNAME, "Filedata",
                                               CURLFORM_FILE, name,
                                               CURLFORM_END);

                               curl_formadd(&formpost,
                                               &lastptr,
                                               CURLFORM_COPYNAME, "Filename",
                                               CURLFORM_COPYCONTENTS, name,
                                               CURLFORM_END);

                               curl = curl_easy_init();

                               struct curl_slist *global_headers=NULL;
                               global_headers = 
curl_slist_append(global_headers, "Content-Type: multipart/form-data");

                               if(curl) {
                                               curl_easy_setopt(curl, 
CURLOPT_URL, url);
                                               curl_easy_setopt(curl, 
CURLOPT_HTTPHEADER, global_headers);
                                               curl_easy_setopt(curl, 
CURLOPT_HTTPPOST, formpost);
                                               curl_easy_setopt(curl, 
CURLOPT_VERBOSE, 1L);
                                               res = curl_easy_perform(curl);

                                               curl_easy_cleanup(curl);
                                               curl_formfree(formpost);
                                               curl_slist_free_all 
(global_headers);
                                               curl_slist_free_all (headers);
                               }

Thank you in advance!
  Eugeny
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to