Name
form:AddStream -- add stream data to a multipart/formdata HTTP POST
Synopsis
form:AddStream(name, len, func[, userdata, type, filename, headers])
Function
form:AddStream() is used to append a stream data section when building a multipart/formdata HTTP POST (sometimes referred to as RFC 2388-style posts). Once you've added all the sections you want included, pass the form handle as parameter to #CURLOPT_HTTPPOST. See easy:SetOpt_HTTPPost for details.

You must call form:Free() after the form post has been done to free the resources.

Using POST with HTTP 1.1 implies the use of a "Expect: 100-continue" header. You can disable this header with #CURLOPT_HTTPHEADER as usual.

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.

The name argument must be a string which provides the name of this part. The name is not allowed to contain zero-valued bytes.

The len parameter must contain the number of bytes to add. The func parameter must be a callback function which will be called to provide the actual data to add. This callback function will be called repeatedly until it has returned exactly len bytes. The callback function behaves exactly like the one in #CURLOPT_READFUNCTION. See easy:SetOpt_ReadFunction for details. If you pass the optional userdata argument, the value you specify here (it can be of any type) will be passed as the second parameter to your callback function.

The optional argument type can be used to set the content-type for the part. The optional filename argument can be used to set a the desired file name for the stream data. The optional argument headers can be used to specify extra headers for the form POST section. This takes a table containing a list and appends the list of headers to those libcurl automatically generates.

Inputs
name
name of the part
len
number of bytes to stream
func
callback function that provides the stream data
userdata
optional: user data to pass to callback function
type
optional: content-type for the part
filename
optional: filename for the content header
headers
optional: extra headers for the POST section

Show TOC