1*6236dae4SAndroid Build Coastguard Worker--- 2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al. 3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl 4*6236dae4SAndroid Build Coastguard WorkerTitle: curl_formadd 5*6236dae4SAndroid Build Coastguard WorkerSection: 3 6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl 7*6236dae4SAndroid Build Coastguard WorkerSee-also: 8*6236dae4SAndroid Build Coastguard Worker - curl_easy_setopt (3) 9*6236dae4SAndroid Build Coastguard Worker - curl_formfree (3) 10*6236dae4SAndroid Build Coastguard Worker - curl_mime_init (3) 11*6236dae4SAndroid Build Coastguard WorkerProtocol: 12*6236dae4SAndroid Build Coastguard Worker - HTTP 13*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.1 14*6236dae4SAndroid Build Coastguard Worker--- 15*6236dae4SAndroid Build Coastguard Worker 16*6236dae4SAndroid Build Coastguard Worker# NAME 17*6236dae4SAndroid Build Coastguard Worker 18*6236dae4SAndroid Build Coastguard Workercurl_formadd - add a section to a multipart form POST 19*6236dae4SAndroid Build Coastguard Worker 20*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS 21*6236dae4SAndroid Build Coastguard Worker 22*6236dae4SAndroid Build Coastguard Worker~~~c 23*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h> 24*6236dae4SAndroid Build Coastguard Worker 25*6236dae4SAndroid Build Coastguard WorkerCURLFORMcode curl_formadd(struct curl_httppost **firstitem, 26*6236dae4SAndroid Build Coastguard Worker struct curl_httppost **lastitem, ...); 27*6236dae4SAndroid Build Coastguard Worker~~~ 28*6236dae4SAndroid Build Coastguard Worker 29*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION 30*6236dae4SAndroid Build Coastguard Worker 31*6236dae4SAndroid Build Coastguard Worker**This function is deprecated.** Use curl_mime_init(3) instead. 32*6236dae4SAndroid Build Coastguard Worker 33*6236dae4SAndroid Build Coastguard Workercurl_formadd() is used to append sections when building a multipart form 34*6236dae4SAndroid Build Coastguard Workerpost. Append one section at a time until you have added all the sections you 35*6236dae4SAndroid Build Coastguard Workerwant included and then you pass the *firstitem* pointer as parameter to 36*6236dae4SAndroid Build Coastguard WorkerCURLOPT_HTTPPOST(3). *lastitem* is set after each curl_formadd(3) call and 37*6236dae4SAndroid Build Coastguard Workeron repeated invokes it should be left as set to allow repeated invokes to find 38*6236dae4SAndroid Build Coastguard Workerthe end of the list faster. 39*6236dae4SAndroid Build Coastguard Worker 40*6236dae4SAndroid Build Coastguard WorkerAfter the *lastitem* pointer follow the real arguments. 41*6236dae4SAndroid Build Coastguard Worker 42*6236dae4SAndroid Build Coastguard WorkerThe pointers *firstitem* and *lastitem* should both be pointing to 43*6236dae4SAndroid Build Coastguard WorkerNULL in the first call to this function. All list-data is allocated by the 44*6236dae4SAndroid Build Coastguard Workerfunction itself. You must call curl_formfree(3) on the *firstitem* 45*6236dae4SAndroid Build Coastguard Workerafter the form post has been done to free the resources. 46*6236dae4SAndroid Build Coastguard Worker 47*6236dae4SAndroid Build Coastguard WorkerUsing POST with HTTP 1.1 implies the use of a "Expect: 100-continue" header. 48*6236dae4SAndroid Build Coastguard WorkerYou can disable this header with CURLOPT_HTTPHEADER(3) as usual. 49*6236dae4SAndroid Build Coastguard Worker 50*6236dae4SAndroid Build Coastguard WorkerFirst, there are some basics you need to understand about multipart form 51*6236dae4SAndroid Build Coastguard Workerposts. Each part consists of at least a NAME and a CONTENTS part. If the part 52*6236dae4SAndroid Build Coastguard Workeris made for file upload, there are also a stored CONTENT-TYPE and a FILENAME. 53*6236dae4SAndroid Build Coastguard WorkerBelow, we discuss what options you use to set these properties in the parts 54*6236dae4SAndroid Build Coastguard Workeryou want to add to your post. 55*6236dae4SAndroid Build Coastguard Worker 56*6236dae4SAndroid Build Coastguard WorkerThe options listed first are for making normal parts. The options from 57*6236dae4SAndroid Build Coastguard Worker*CURLFORM_FILE* through *CURLFORM_BUFFERLENGTH* are for file upload 58*6236dae4SAndroid Build Coastguard Workerparts. 59*6236dae4SAndroid Build Coastguard Worker 60*6236dae4SAndroid Build Coastguard Worker# OPTIONS 61*6236dae4SAndroid Build Coastguard Worker 62*6236dae4SAndroid Build Coastguard Worker## CURLFORM_COPYNAME 63*6236dae4SAndroid Build Coastguard Worker 64*6236dae4SAndroid Build Coastguard Workerfollowed by a string which provides the *name* of this part. libcurl 65*6236dae4SAndroid Build Coastguard Workercopies the string so your application does not need to keep it around after 66*6236dae4SAndroid Build Coastguard Workerthis function call. If the name is not null-terminated, you must set its 67*6236dae4SAndroid Build Coastguard Workerlength with **CURLFORM_NAMELENGTH**. The *name* is not allowed to 68*6236dae4SAndroid Build Coastguard Workercontain zero-valued bytes. The copied data is freed by curl_formfree(3). 69*6236dae4SAndroid Build Coastguard Worker 70*6236dae4SAndroid Build Coastguard Worker## CURLFORM_PTRNAME 71*6236dae4SAndroid Build Coastguard Worker 72*6236dae4SAndroid Build Coastguard Workerfollowed by a string which provides the *name* of this part. libcurl uses the 73*6236dae4SAndroid Build Coastguard Workerpointer and refer to the data in your application, so you must make sure it 74*6236dae4SAndroid Build Coastguard Workerremains until curl no longer needs it. If the name is not null-terminated, you 75*6236dae4SAndroid Build Coastguard Workermust set its length with **CURLFORM_NAMELENGTH**. The *name* is not allowed to 76*6236dae4SAndroid Build Coastguard Workercontain zero-valued bytes. 77*6236dae4SAndroid Build Coastguard Worker 78*6236dae4SAndroid Build Coastguard Worker## CURLFORM_COPYCONTENTS 79*6236dae4SAndroid Build Coastguard Worker 80*6236dae4SAndroid Build Coastguard Workerfollowed by a pointer to the contents of this part, the actual data to send 81*6236dae4SAndroid Build Coastguard Workeraway. libcurl copies the provided data, so your application does not need to 82*6236dae4SAndroid Build Coastguard Workerkeep it around after this function call. If the data is not null terminated, 83*6236dae4SAndroid Build Coastguard Workeror if you would like it to contain zero bytes, you must set the length of the 84*6236dae4SAndroid Build Coastguard Workername with **CURLFORM_CONTENTSLENGTH**. The copied data is freed by 85*6236dae4SAndroid Build Coastguard Workercurl_formfree(3). 86*6236dae4SAndroid Build Coastguard Worker 87*6236dae4SAndroid Build Coastguard Worker## CURLFORM_PTRCONTENTS 88*6236dae4SAndroid Build Coastguard Worker 89*6236dae4SAndroid Build Coastguard Workerfollowed by a pointer to the contents of this part, the actual data to send 90*6236dae4SAndroid Build Coastguard Workeraway. libcurl uses the pointer and refer to the data in your application, so 91*6236dae4SAndroid Build Coastguard Workeryou must make sure it remains until curl no longer needs it. If the data is 92*6236dae4SAndroid Build Coastguard Workernot null-terminated, or if you would like it to contain zero bytes, you must 93*6236dae4SAndroid Build Coastguard Workerset its length with **CURLFORM_CONTENTSLENGTH**. 94*6236dae4SAndroid Build Coastguard Worker 95*6236dae4SAndroid Build Coastguard Worker## CURLFORM_CONTENTLEN 96*6236dae4SAndroid Build Coastguard Worker 97*6236dae4SAndroid Build Coastguard Workerfollowed by a curl_off_t value giving the length of the contents. Note that 98*6236dae4SAndroid Build Coastguard Workerfor *CURLFORM_STREAM* contents, this option is mandatory. 99*6236dae4SAndroid Build Coastguard Worker 100*6236dae4SAndroid Build Coastguard WorkerIf you pass a 0 (zero) for this option, libcurl calls strlen() on the contents 101*6236dae4SAndroid Build Coastguard Workerto figure out the size. If you really want to send a zero byte content then 102*6236dae4SAndroid Build Coastguard Workeryou must make sure strlen() on the data pointer returns zero. 103*6236dae4SAndroid Build Coastguard Worker 104*6236dae4SAndroid Build Coastguard Worker(Option added in 7.46.0) 105*6236dae4SAndroid Build Coastguard Worker 106*6236dae4SAndroid Build Coastguard Worker## CURLFORM_CONTENTSLENGTH 107*6236dae4SAndroid Build Coastguard Worker 108*6236dae4SAndroid Build Coastguard Worker(This option is deprecated. Use *CURLFORM_CONTENTLEN* instead.) 109*6236dae4SAndroid Build Coastguard Worker 110*6236dae4SAndroid Build Coastguard Workerfollowed by a long giving the length of the contents. Note that for 111*6236dae4SAndroid Build Coastguard Worker*CURLFORM_STREAM* contents, this option is mandatory. 112*6236dae4SAndroid Build Coastguard Worker 113*6236dae4SAndroid Build Coastguard WorkerIf you pass a 0 (zero) for this option, libcurl calls strlen() on the contents 114*6236dae4SAndroid Build Coastguard Workerto figure out the size. If you really want to send a zero byte content then 115*6236dae4SAndroid Build Coastguard Workeryou must make sure strlen() on the data pointer returns zero. 116*6236dae4SAndroid Build Coastguard Worker 117*6236dae4SAndroid Build Coastguard Worker## CURLFORM_FILECONTENT 118*6236dae4SAndroid Build Coastguard Worker 119*6236dae4SAndroid Build Coastguard Workerfollowed by a filename, causes that file to be read and its contents used 120*6236dae4SAndroid Build Coastguard Workeras data in this part. This part does *not* automatically become a file 121*6236dae4SAndroid Build Coastguard Workerupload part simply because its data was read from a file. 122*6236dae4SAndroid Build Coastguard Worker 123*6236dae4SAndroid Build Coastguard WorkerThe specified file needs to kept around until the associated transfer is done. 124*6236dae4SAndroid Build Coastguard Worker 125*6236dae4SAndroid Build Coastguard Worker## CURLFORM_FILE 126*6236dae4SAndroid Build Coastguard Worker 127*6236dae4SAndroid Build Coastguard Workerfollowed by a filename, makes this part a file upload part. It sets the 128*6236dae4SAndroid Build Coastguard Worker*filename* field to the basename of the provided filename, it reads the 129*6236dae4SAndroid Build Coastguard Workercontents of the file and passes them as data and sets the content-type if the 130*6236dae4SAndroid Build Coastguard Workergiven file match one of the internally known file extensions. For 131*6236dae4SAndroid Build Coastguard Worker**CURLFORM_FILE** the user may send one or more files in one part by 132*6236dae4SAndroid Build Coastguard Workerproviding multiple **CURLFORM_FILE** arguments each followed by the filename 133*6236dae4SAndroid Build Coastguard Worker(and each *CURLFORM_FILE* is allowed to have a 134*6236dae4SAndroid Build Coastguard Worker*CURLFORM_CONTENTTYPE*). 135*6236dae4SAndroid Build Coastguard Worker 136*6236dae4SAndroid Build Coastguard WorkerThe given upload file has to exist in its full in the file system already when 137*6236dae4SAndroid Build Coastguard Workerthe upload starts, as libcurl needs to read the correct file size beforehand. 138*6236dae4SAndroid Build Coastguard Worker 139*6236dae4SAndroid Build Coastguard WorkerThe specified file needs to kept around until the associated transfer is done. 140*6236dae4SAndroid Build Coastguard Worker 141*6236dae4SAndroid Build Coastguard Worker## CURLFORM_CONTENTTYPE 142*6236dae4SAndroid Build Coastguard Worker 143*6236dae4SAndroid Build Coastguard Workeris used in combination with *CURLFORM_FILE*. Followed by a pointer to a 144*6236dae4SAndroid Build Coastguard Workerstring which provides the content-type for this part, possibly instead of an 145*6236dae4SAndroid Build Coastguard Workerinternally chosen one. 146*6236dae4SAndroid Build Coastguard Worker 147*6236dae4SAndroid Build Coastguard Worker## CURLFORM_FILENAME 148*6236dae4SAndroid Build Coastguard Worker 149*6236dae4SAndroid Build Coastguard Workeris used in combination with *CURLFORM_FILE*. Followed by a pointer to a 150*6236dae4SAndroid Build Coastguard Workerstring, it tells libcurl to use the given string as the *filename* in the file 151*6236dae4SAndroid Build Coastguard Workerupload part instead of the actual filename. 152*6236dae4SAndroid Build Coastguard Worker 153*6236dae4SAndroid Build Coastguard Worker## CURLFORM_BUFFER 154*6236dae4SAndroid Build Coastguard Worker 155*6236dae4SAndroid Build Coastguard Workeris used for custom file upload parts without use of *CURLFORM_FILE*. It 156*6236dae4SAndroid Build Coastguard Workertells libcurl that the file contents are already present in a buffer. The 157*6236dae4SAndroid Build Coastguard Workerparameter is a string which provides the *filename* field in the content 158*6236dae4SAndroid Build Coastguard Workerheader. 159*6236dae4SAndroid Build Coastguard Worker 160*6236dae4SAndroid Build Coastguard Worker## CURLFORM_BUFFERPTR 161*6236dae4SAndroid Build Coastguard Worker 162*6236dae4SAndroid Build Coastguard Workeris used in combination with *CURLFORM_BUFFER*. The parameter is a pointer 163*6236dae4SAndroid Build Coastguard Workerto the buffer to be uploaded. This buffer must not be freed until after 164*6236dae4SAndroid Build Coastguard Workercurl_easy_cleanup(3) is called. You must also use 165*6236dae4SAndroid Build Coastguard Worker*CURLFORM_BUFFERLENGTH* to set the number of bytes in the buffer. 166*6236dae4SAndroid Build Coastguard Worker 167*6236dae4SAndroid Build Coastguard Worker## CURLFORM_BUFFERLENGTH 168*6236dae4SAndroid Build Coastguard Worker 169*6236dae4SAndroid Build Coastguard Workeris used in combination with *CURLFORM_BUFFER*. The parameter is a 170*6236dae4SAndroid Build Coastguard Workerlong which gives the length of the buffer. 171*6236dae4SAndroid Build Coastguard Worker 172*6236dae4SAndroid Build Coastguard Worker## CURLFORM_STREAM 173*6236dae4SAndroid Build Coastguard Worker 174*6236dae4SAndroid Build Coastguard WorkerTells libcurl to use the CURLOPT_READFUNCTION(3) callback to get 175*6236dae4SAndroid Build Coastguard Workerdata. The parameter you pass to *CURLFORM_STREAM* is the pointer passed on 176*6236dae4SAndroid Build Coastguard Workerto the read callback's fourth argument. If you want the part to look like a 177*6236dae4SAndroid Build Coastguard Workerfile upload one, set the *CURLFORM_FILENAME* parameter as well. Note that 178*6236dae4SAndroid Build Coastguard Workerwhen using *CURLFORM_STREAM*, *CURLFORM_CONTENTSLENGTH* must also be 179*6236dae4SAndroid Build Coastguard Workerset with the total expected length of the part unless the formpost is sent 180*6236dae4SAndroid Build Coastguard Workerchunked encoded. (Option added in libcurl 7.18.2) 181*6236dae4SAndroid Build Coastguard Worker 182*6236dae4SAndroid Build Coastguard Worker## CURLFORM_ARRAY 183*6236dae4SAndroid Build Coastguard Worker 184*6236dae4SAndroid Build Coastguard WorkerAnother possibility to send options to curl_formadd() is the 185*6236dae4SAndroid Build Coastguard Worker**CURLFORM_ARRAY** option, that passes a struct curl_forms array pointer as 186*6236dae4SAndroid Build Coastguard Workerits value. Each curl_forms structure element has a *CURLformoption* and a 187*6236dae4SAndroid Build Coastguard Workerchar pointer. The final element in the array must be a CURLFORM_END. All 188*6236dae4SAndroid Build Coastguard Workeravailable options can be used in an array, except the CURLFORM_ARRAY option 189*6236dae4SAndroid Build Coastguard Workeritself. The last argument in such an array must always be **CURLFORM_END**. 190*6236dae4SAndroid Build Coastguard Worker 191*6236dae4SAndroid Build Coastguard Worker## CURLFORM_CONTENTHEADER 192*6236dae4SAndroid Build Coastguard Worker 193*6236dae4SAndroid Build Coastguard Workerspecifies extra headers for the form POST section. This takes a curl_slist 194*6236dae4SAndroid Build Coastguard Workerprepared in the usual way using **curl_slist_append** and appends the list 195*6236dae4SAndroid Build Coastguard Workerof headers to those libcurl automatically generates. The list must exist while 196*6236dae4SAndroid Build Coastguard Workerthe POST occurs, if you free it before the post completes you may experience 197*6236dae4SAndroid Build Coastguard Workerproblems. 198*6236dae4SAndroid Build Coastguard Worker 199*6236dae4SAndroid Build Coastguard WorkerWhen you have passed the *struct curl_httppost* pointer to 200*6236dae4SAndroid Build Coastguard Workercurl_easy_setopt(3) (using the CURLOPT_HTTPPOST(3) option), you 201*6236dae4SAndroid Build Coastguard Workermust not free the list until after you have called curl_easy_cleanup(3) 202*6236dae4SAndroid Build Coastguard Workerfor the curl handle. 203*6236dae4SAndroid Build Coastguard Worker 204*6236dae4SAndroid Build Coastguard WorkerSee example below. 205*6236dae4SAndroid Build Coastguard Worker 206*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS% 207*6236dae4SAndroid Build Coastguard Worker 208*6236dae4SAndroid Build Coastguard Worker# EXAMPLE 209*6236dae4SAndroid Build Coastguard Worker 210*6236dae4SAndroid Build Coastguard Worker~~~c 211*6236dae4SAndroid Build Coastguard Worker#include <string.h> /* for strlen */ 212*6236dae4SAndroid Build Coastguard Worker 213*6236dae4SAndroid Build Coastguard Workerstatic const char record[]="data in a buffer"; 214*6236dae4SAndroid Build Coastguard Worker 215*6236dae4SAndroid Build Coastguard Workerint main(void) 216*6236dae4SAndroid Build Coastguard Worker{ 217*6236dae4SAndroid Build Coastguard Worker CURL *curl = curl_easy_init(); 218*6236dae4SAndroid Build Coastguard Worker if(curl) { 219*6236dae4SAndroid Build Coastguard Worker struct curl_httppost *post = NULL; 220*6236dae4SAndroid Build Coastguard Worker struct curl_httppost *last = NULL; 221*6236dae4SAndroid Build Coastguard Worker char namebuffer[] = "name buffer"; 222*6236dae4SAndroid Build Coastguard Worker long namelength = strlen(namebuffer); 223*6236dae4SAndroid Build Coastguard Worker char buffer[] = "test buffer"; 224*6236dae4SAndroid Build Coastguard Worker char htmlbuffer[] = "<HTML>test buffer</HTML>"; 225*6236dae4SAndroid Build Coastguard Worker long htmlbufferlength = strlen(htmlbuffer); 226*6236dae4SAndroid Build Coastguard Worker struct curl_forms forms[3]; 227*6236dae4SAndroid Build Coastguard Worker char file1[] = "my-face.jpg"; 228*6236dae4SAndroid Build Coastguard Worker char file2[] = "your-face.jpg"; 229*6236dae4SAndroid Build Coastguard Worker /* add null character into htmlbuffer, to demonstrate that 230*6236dae4SAndroid Build Coastguard Worker transfers of buffers containing null characters actually work 231*6236dae4SAndroid Build Coastguard Worker */ 232*6236dae4SAndroid Build Coastguard Worker htmlbuffer[8] = '\0'; 233*6236dae4SAndroid Build Coastguard Worker 234*6236dae4SAndroid Build Coastguard Worker /* Add simple name/content section */ 235*6236dae4SAndroid Build Coastguard Worker curl_formadd(&post, &last, CURLFORM_COPYNAME, "name", 236*6236dae4SAndroid Build Coastguard Worker CURLFORM_COPYCONTENTS, "content", CURLFORM_END); 237*6236dae4SAndroid Build Coastguard Worker 238*6236dae4SAndroid Build Coastguard Worker /* Add simple name/content/contenttype section */ 239*6236dae4SAndroid Build Coastguard Worker curl_formadd(&post, &last, CURLFORM_COPYNAME, "htmlcode", 240*6236dae4SAndroid Build Coastguard Worker CURLFORM_COPYCONTENTS, "<HTML></HTML>", 241*6236dae4SAndroid Build Coastguard Worker CURLFORM_CONTENTTYPE, "text/html", CURLFORM_END); 242*6236dae4SAndroid Build Coastguard Worker 243*6236dae4SAndroid Build Coastguard Worker /* Add name/ptrcontent section */ 244*6236dae4SAndroid Build Coastguard Worker curl_formadd(&post, &last, CURLFORM_COPYNAME, "name_for_ptrcontent", 245*6236dae4SAndroid Build Coastguard Worker CURLFORM_PTRCONTENTS, buffer, CURLFORM_END); 246*6236dae4SAndroid Build Coastguard Worker 247*6236dae4SAndroid Build Coastguard Worker /* Add ptrname/ptrcontent section */ 248*6236dae4SAndroid Build Coastguard Worker curl_formadd(&post, &last, CURLFORM_PTRNAME, namebuffer, 249*6236dae4SAndroid Build Coastguard Worker CURLFORM_PTRCONTENTS, buffer, CURLFORM_NAMELENGTH, 250*6236dae4SAndroid Build Coastguard Worker namelength, CURLFORM_END); 251*6236dae4SAndroid Build Coastguard Worker 252*6236dae4SAndroid Build Coastguard Worker /* Add name/ptrcontent/contenttype section */ 253*6236dae4SAndroid Build Coastguard Worker curl_formadd(&post, &last, CURLFORM_COPYNAME, "html_code_with_hole", 254*6236dae4SAndroid Build Coastguard Worker CURLFORM_PTRCONTENTS, htmlbuffer, 255*6236dae4SAndroid Build Coastguard Worker CURLFORM_CONTENTSLENGTH, htmlbufferlength, 256*6236dae4SAndroid Build Coastguard Worker CURLFORM_CONTENTTYPE, "text/html", CURLFORM_END); 257*6236dae4SAndroid Build Coastguard Worker 258*6236dae4SAndroid Build Coastguard Worker /* Add simple file section */ 259*6236dae4SAndroid Build Coastguard Worker curl_formadd(&post, &last, CURLFORM_COPYNAME, "picture", 260*6236dae4SAndroid Build Coastguard Worker CURLFORM_FILE, "my-face.jpg", CURLFORM_END); 261*6236dae4SAndroid Build Coastguard Worker 262*6236dae4SAndroid Build Coastguard Worker /* Add file/contenttype section */ 263*6236dae4SAndroid Build Coastguard Worker curl_formadd(&post, &last, CURLFORM_COPYNAME, "picture", 264*6236dae4SAndroid Build Coastguard Worker CURLFORM_FILE, "my-face.jpg", 265*6236dae4SAndroid Build Coastguard Worker CURLFORM_CONTENTTYPE, "image/jpeg", CURLFORM_END); 266*6236dae4SAndroid Build Coastguard Worker 267*6236dae4SAndroid Build Coastguard Worker /* Add two file section */ 268*6236dae4SAndroid Build Coastguard Worker curl_formadd(&post, &last, CURLFORM_COPYNAME, "pictures", 269*6236dae4SAndroid Build Coastguard Worker CURLFORM_FILE, "my-face.jpg", 270*6236dae4SAndroid Build Coastguard Worker CURLFORM_FILE, "your-face.jpg", CURLFORM_END); 271*6236dae4SAndroid Build Coastguard Worker 272*6236dae4SAndroid Build Coastguard Worker /* Add two file section using CURLFORM_ARRAY */ 273*6236dae4SAndroid Build Coastguard Worker forms[0].option = CURLFORM_FILE; 274*6236dae4SAndroid Build Coastguard Worker forms[0].value = file1; 275*6236dae4SAndroid Build Coastguard Worker forms[1].option = CURLFORM_FILE; 276*6236dae4SAndroid Build Coastguard Worker forms[1].value = file2; 277*6236dae4SAndroid Build Coastguard Worker forms[2].option = CURLFORM_END; 278*6236dae4SAndroid Build Coastguard Worker 279*6236dae4SAndroid Build Coastguard Worker /* Add a buffer to upload */ 280*6236dae4SAndroid Build Coastguard Worker curl_formadd(&post, &last, 281*6236dae4SAndroid Build Coastguard Worker CURLFORM_COPYNAME, "name", 282*6236dae4SAndroid Build Coastguard Worker CURLFORM_BUFFER, "data", 283*6236dae4SAndroid Build Coastguard Worker CURLFORM_BUFFERPTR, record, 284*6236dae4SAndroid Build Coastguard Worker CURLFORM_BUFFERLENGTH, sizeof(record), 285*6236dae4SAndroid Build Coastguard Worker CURLFORM_END); 286*6236dae4SAndroid Build Coastguard Worker 287*6236dae4SAndroid Build Coastguard Worker /* no option needed for the end marker */ 288*6236dae4SAndroid Build Coastguard Worker curl_formadd(&post, &last, CURLFORM_COPYNAME, "pictures", 289*6236dae4SAndroid Build Coastguard Worker CURLFORM_ARRAY, forms, CURLFORM_END); 290*6236dae4SAndroid Build Coastguard Worker /* Add the content of a file as a normal post text value */ 291*6236dae4SAndroid Build Coastguard Worker curl_formadd(&post, &last, CURLFORM_COPYNAME, "filecontent", 292*6236dae4SAndroid Build Coastguard Worker CURLFORM_FILECONTENT, ".bashrc", CURLFORM_END); 293*6236dae4SAndroid Build Coastguard Worker /* Set the form info */ 294*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_HTTPPOST, post); 295*6236dae4SAndroid Build Coastguard Worker 296*6236dae4SAndroid Build Coastguard Worker curl_easy_perform(curl); 297*6236dae4SAndroid Build Coastguard Worker 298*6236dae4SAndroid Build Coastguard Worker curl_easy_cleanup(curl); 299*6236dae4SAndroid Build Coastguard Worker 300*6236dae4SAndroid Build Coastguard Worker curl_formfree(post); 301*6236dae4SAndroid Build Coastguard Worker } 302*6236dae4SAndroid Build Coastguard Worker} 303*6236dae4SAndroid Build Coastguard Worker~~~ 304*6236dae4SAndroid Build Coastguard Worker 305*6236dae4SAndroid Build Coastguard Worker# DEPRECATED 306*6236dae4SAndroid Build Coastguard Worker 307*6236dae4SAndroid Build Coastguard WorkerDeprecated in 7.56.0. Before this release, field names were allowed to contain 308*6236dae4SAndroid Build Coastguard Workerzero-valued bytes. The pseudo-filename "-" to read stdin is discouraged 309*6236dae4SAndroid Build Coastguard Workeralthough still supported, but data is not read before being actually sent: the 310*6236dae4SAndroid Build Coastguard Workereffective data size can then not be automatically determined, resulting in a 311*6236dae4SAndroid Build Coastguard Workerchunked encoding transfer. Backslashes and double quotes in field and 312*6236dae4SAndroid Build Coastguard Workerfilenames are now escaped before transmission. 313*6236dae4SAndroid Build Coastguard Worker 314*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY% 315*6236dae4SAndroid Build Coastguard Worker 316*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE 317*6236dae4SAndroid Build Coastguard Worker 318*6236dae4SAndroid Build Coastguard Worker0 means everything was OK, non-zero means an error occurred corresponding to a 319*6236dae4SAndroid Build Coastguard WorkerCURL_FORMADD_* constant defined in *\<curl/curl.h\>*. 320