~ubuntu-branches/ubuntu/lucid/curl/lucid-201101212007

« back to all changes in this revision

Viewing changes to docs/libcurl/curl_formadd.html

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-05-16 15:16:54 UTC
  • mto: (3.1.1 lenny) (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: james.westby@ubuntu.com-20070516151654-x9nkigtr2j0i8d0v
Tags: upstream-7.16.2
ImportĀ upstreamĀ versionĀ 7.16.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
<p class="level0"><a name="DESCRIPTION"></a><h2 class="nroffsh">DESCRIPTION</h2>
51
51
<p class="level0">curl_formadd() is used to append sections when building a multipart/formdata HTTP POST (sometimes referred to as rfc1867-style posts). Append one section at a time until you've added all the sections you want included and then you pass the <span Class="emphasis">firstitem</span> pointer as parameter to <span Class="bold">CURLOPT_HTTPPOST</span>. <span Class="emphasis">lastitem</span> is set after each call and on repeated invokes it should be left as set to allow repeated invokes to find the end of the list faster. 
52
52
<p class="level0">After the <span Class="emphasis">lastitem</span> pointer follow the real arguments. 
53
 
<p class="level0">The pointers <span Class="emphasis">*firstitem</span> and <span Class="emphasis">*lastitem</span> should both be pointing to NULL in the first call to this function. All list-data will be allocated by the function itself. You must call <span Class="emphasis">curl_formfree</span> after the form post has been done to free the resources again. 
 
53
<p class="level0">The pointers <span Class="emphasis">*firstitem</span> and <span Class="emphasis">*lastitem</span> should both be pointing to NULL in the first call to this function. All list-data will be allocated by the function itself. You must call <a class="emphasis" href="./curl_formfree.html">curl_formfree(3)</a> after the form post has been done to free the resources. 
54
54
<p class="level0">Using POST with HTTP 1.1 implies the use of a "Expect: 100-continue" header. You can disable this header with <span Class="emphasis">CURLOPT_HTTPHEADER</span> as usual. 
55
 
<p class="level0">First, there are some basics you need to understand about multipart/formdata posts. Each part consists of at least a NAME and a CONTENTS part. If the part is made for file upload, there are also a stored CONTENT-TYPE and a FILENAME. Below here, we'll discuss on what options you use to set these properties in the parts you want to add to your post. <a name="OPTIONS"></a><h2 class="nroffsh">OPTIONS</h2>
 
55
<p class="level0">First, there are some basics you need to understand about multipart/formdata posts. Each part consists of at least a NAME and a CONTENTS part. If the part is made for file upload, there are also a stored CONTENT-TYPE and a FILENAME. Below, we'll discuss what options you use to set these properties in the parts you want to add to your post. 
 
56
<p class="level0">The options listed first are for making normal parts. The options from <a class="emphasis" href="#CURLFORMFILE">CURLFORM_FILE</a> through <a class="emphasis" href="#CURLFORMBUFFERLENGTH">CURLFORM_BUFFERLENGTH</a> are for file upload parts. 
 
57
<p class="level0"><a name="OPTIONS"></a><h2 class="nroffsh">OPTIONS</h2>
 
58
<p class="level0">
56
59
<p class="level0">
57
60
<p class="level0"><a name="CURLFORMCOPYNAME"></a><span class="nroffip">CURLFORM_COPYNAME</span> 
58
 
<p class="level1">followed by string is used to set the name of this part. libcurl copies the given data, so your application doesn't need to keep it around after this function call. If the name isn't zero terminated properly, or if you'd like it to contain zero bytes, you need to set the length of the name with <span Class="bold">CURLFORM_NAMELENGTH</span>. 
 
61
<p class="level1">followed by a string which provides the <span Class="emphasis">name</span> of this part. libcurl copies the string so your application doesn't need to keep it around after this function call. If the name isn't null terminated, or if you'd like it to contain zero bytes, you must set its length with <span Class="bold">CURLFORM_NAMELENGTH</span>. The copied data will be freed by <a class="emphasis" href="./curl_formfree.html">curl_formfree(3)</a>. 
59
62
<p class="level1">
60
63
<p class="level0"><a name="CURLFORMPTRNAME"></a><span class="nroffip">CURLFORM_PTRNAME</span> 
61
 
<p class="level1">followed by a string is used for the name of this part. libcurl will use the pointer and refer to the data in your application, you must make sure it remains until curl no longer needs it. If the name isn't zero terminated properly, or if you'd like it to contain zero bytes, you need to set the length of the name with <span Class="bold">CURLFORM_NAMELENGTH</span>. 
 
64
<p class="level1">followed by a string which provides the <span Class="emphasis">name</span> of this part. libcurl will use the pointer and refer to the data in your application, so you must make sure it remains until curl no longer needs it. If the name isn't null terminated, or if you'd like it to contain zero bytes, you must set its length with <span Class="bold">CURLFORM_NAMELENGTH</span>. 
62
65
<p class="level1">
63
66
<p class="level0"><a name="CURLFORMCOPYCONTENTS"></a><span class="nroffip">CURLFORM_COPYCONTENTS</span> 
64
 
<p class="level1">followed by a string is used for the contents of this part, the actual data to send away. libcurl copies the given data, so your application doesn't need to keep it around after this function call. If the data isn't zero terminated properly, or if you'd like it to contain zero bytes, you need to set the length of the name with <a class="bold" href="#CURLFORMCONTENTSLENGTH">CURLFORM_CONTENTSLENGTH</a>. 
 
67
<p class="level1">followed by a pointer to the contents of this part, the actual data to send away. libcurl copies the provided data, so your application doesn't need to keep it around after this function call. If the data isn't null terminated, or if you'd like it to contain zero bytes, you must set the length of the name with <a class="bold" href="#CURLFORMCONTENTSLENGTH">CURLFORM_CONTENTSLENGTH</a>. The copied data will be freed by <a class="emphasis" href="./curl_formfree.html">curl_formfree(3)</a>. 
65
68
<p class="level1">
66
69
<p class="level0"><a name="CURLFORMPTRCONTENTS"></a><span class="nroffip">CURLFORM_PTRCONTENTS</span> 
67
 
<p class="level1">followed by a string is used for the contents of this part, the actual data to send away. libcurl will use the pointer and refer to the data in your application, you must make sure it remains until curl no longer needs it. If the data isn't zero terminated properly, or if you'd like it to contain zero bytes, you need to set the length of the name with <a class="bold" href="#CURLFORMCONTENTSLENGTH">CURLFORM_CONTENTSLENGTH</a>. 
 
70
<p class="level1">followed by a pointer to the contents of this part, the actual data to send away. libcurl will use the pointer and refer to the data in your application, so you must make sure it remains until curl no longer needs it. If the data isn't null terminated, or if you'd like it to contain zero bytes, you must set its length  with <a class="bold" href="#CURLFORMCONTENTSLENGTH">CURLFORM_CONTENTSLENGTH</a>. 
68
71
<p class="level1">
69
72
<p class="level0"><a name="CURLFORMCONTENTSLENGTH"></a><span class="nroffip">CURLFORM_CONTENTSLENGTH</span> 
70
 
<p class="level1">followed by a long setting the length of the contents. 
 
73
<p class="level1">followed by a long giving the length of the contents. 
71
74
<p class="level1">
72
75
<p class="level0"><a name="CURLFORMFILECONTENT"></a><span class="nroffip">CURLFORM_FILECONTENT</span> 
73
 
<p class="level1">followed by a file name, makes that file read and the contents will be used in as data in this part. 
 
76
<p class="level1">followed by a filename, causes that file to be read and its contents used as data in this part. This part does <span Class="emphasis">not</span> automatically become a file upload part simply because its data was read from a file. 
74
77
<p class="level1">
75
78
<p class="level0"><a name="CURLFORMFILE"></a><span class="nroffip">CURLFORM_FILE</span> 
76
 
<p class="level1">followed by a file name, makes this part a file upload part. It sets the file name field to the actual file name used here, it gets the contents of the file and passes as data and sets the content-type if the given file match one of the new internally known file extension.  For <a class="bold" href="#CURLFORMFILE">CURLFORM_FILE</a> the user may send one or more files in one part by providing multiple <a class="bold" href="#CURLFORMFILE">CURLFORM_FILE</a> arguments each followed by the filename (and each CURLFORM_FILE is allowed to have a CURLFORM_CONTENTTYPE). 
 
79
<p class="level1">followed by a filename, makes this part a file upload part. It sets the <span Class="emphasis">filename</span> field to the basename of the provided filename, it reads the contents of the file and passes them as data and sets the content-type if the given file match one of the internally known file extensions.  For <a class="bold" href="#CURLFORMFILE">CURLFORM_FILE</a> the user may send one or more files in one part by providing multiple <a class="bold" href="#CURLFORMFILE">CURLFORM_FILE</a> arguments each followed by the filename (and each CURLFORM_FILE is allowed to have a CURLFORM_CONTENTTYPE). 
77
80
<p class="level1">
78
81
<p class="level0"><a name="CURLFORMCONTENTTYPE"></a><span class="nroffip">CURLFORM_CONTENTTYPE</span> 
79
 
<p class="level1">followed by a pointer to a string with a content-type will make curl use this given content-type for this file upload part, possibly instead of an internally chosen one. 
 
82
<p class="level1">is used in combination with <a class="emphasis" href="#CURLFORMFILE">CURLFORM_FILE</a>. Followed by a pointer to a string which provides the content-type for this part, possibly instead of an internally chosen one. 
80
83
<p class="level1">
81
84
<p class="level0"><a name="CURLFORMFILENAME"></a><span class="nroffip">CURLFORM_FILENAME</span> 
82
 
<p class="level1">followed by a pointer to a string to a name, will make libcurl use the given name in the file upload part, instead of the actual file name given to <a class="emphasis" href="#CURLFORMFILE">CURLFORM_FILE</a>. 
 
85
<p class="level1">is used in combination with <a class="emphasis" href="#CURLFORMFILE">CURLFORM_FILE</a>. Followed by a pointer to a string, it tells libcurl to use the given string as the <span Class="emphasis">filename</span> in the file upload part instead of the actual file name. 
83
86
<p class="level1">
84
87
<p class="level0"><a name="CURLFORMBUFFER"></a><span class="nroffip">CURLFORM_BUFFER</span> 
85
 
<p class="level1">followed by a string, tells libcurl that a buffer is to be used to upload data instead of using a file. The given string is used as the value of the file name field in the content header. 
 
88
<p class="level1">is used for custom file upload parts without use of <a class="emphasis" href="#CURLFORMFILE">CURLFORM_FILE</a>.  It tells libcurl that the file contents are already present in a buffer.  The parameter is a string which provides the <span Class="emphasis">filename</span> field in the content header. 
86
89
<p class="level1">
87
90
<p class="level0"><a name="CURLFORMBUFFERPTR"></a><span class="nroffip">CURLFORM_BUFFERPTR</span> 
88
 
<p class="level1">followed by a pointer to a data area, tells libcurl the address of the buffer containing data to upload (as indicated with <a class="emphasis" href="#CURLFORMBUFFER">CURLFORM_BUFFER</a>). The buffer containing this data must not be freed until after <a class="emphasis" href="./curl_easy_cleanup.html">curl_easy_cleanup(3)</a> is called. You must also use <a class="emphasis" href="#CURLFORMBUFFERLENGTH">CURLFORM_BUFFERLENGTH</a> to set the length of the given buffer area. 
 
91
<p class="level1">is used in combination with <a class="emphasis" href="#CURLFORMBUFFER">CURLFORM_BUFFER</a>. The parameter is a pointer to the buffer to be uploaded. This buffer must not be freed until after <a class="emphasis" href="./curl_easy_cleanup.html">curl_easy_cleanup(3)</a> is called. You must also use <a class="emphasis" href="#CURLFORMBUFFERLENGTH">CURLFORM_BUFFERLENGTH</a> to set the number of bytes in the buffer. 
89
92
<p class="level1">
90
93
<p class="level0"><a name="CURLFORMBUFFERLENGTH"></a><span class="nroffip">CURLFORM_BUFFERLENGTH</span> 
91
 
<p class="level1">followed by a long with the size of the <a class="emphasis" href="#CURLFORMBUFFERPTR">CURLFORM_BUFFERPTR</a> data area, tells libcurl the length of the buffer to upload. 
 
94
<p class="level1">is used in combination with <a class="emphasis" href="#CURLFORMBUFFER">CURLFORM_BUFFER</a>. The parameter is a long which gives the length of the buffer. 
92
95
<p class="level1">
93
96
<p class="level0"><a name="CURLFORMARRAY"></a><span class="nroffip">CURLFORM_ARRAY</span> 
94
97
<p class="level1">Another possibility to send options to curl_formadd() is the <a class="bold" href="#CURLFORMARRAY">CURLFORM_ARRAY</a> option, that passes a struct curl_forms array pointer as its value. Each curl_forms structure element has a CURLformoption and a char pointer. The final element in the array must be a CURLFORM_END. All available options can be used in an array, except the CURLFORM_ARRAY option itself!  The last argument in such an array must always be <span Class="bold">CURLFORM_END</span>.