// Implementation of add method. void curl_form::add(const curl_pair<CURLformoption,string> &form_name, const curl_pair<CURLformoption,string> &form_content) { if (curl_formadd(&this->form_post,&this->last_ptr, form_name.first(),form_name.second(), form_content.first(),form_content.second(), CURLFORM_END) != 0) { throw curl_error("*** Error while adding the form *** ",__FUNCTION__); } }
void curl_form::add(const curl_pair<CURLformoption,string> &form_name, const curl_pair<CURLformoption,string> &form_content, const curl_pair<CURLformoption,int> &content_length) { if (curl_formadd(&this->form_post,&this->last_ptr, form_name.first(),form_name.second(), form_content.first(),form_content.second(), content_length.first(),content_length.second(), CURLFORM_END) != 0) { throw curl_exception("Error while adding the form",__FUNCTION__); } }
/** * If you want to upload more than one file, you can pass the form name and a * vector of filenames. */ void curl_form::add(const curl_pair<CURLformoption,string> &form_name, const vector<string> &files) { const size_t size = files.size(); struct curl_forms *new_files; this->is_null(new_files = (struct curl_forms *)calloc(size,sizeof(struct curl_forms))); if (new_files == nullptr) { throw bad_alloc(); } for (size_t i = 0; i < size; ++i) { new_files[i].option = CURLFORM_FILE; new_files[i].value = files[i].c_str(); } if (curl_formadd(&this->form_post,&this->last_ptr, form_name.first(),form_name.second(), CURLFORM_ARRAY,new_files, CURLFORM_END) != 0) { delete []new_files; throw curl_exception("Error while adding the form",__FUNCTION__); } delete []new_files; }