Name
form:AddFiles -- add multiple file upload sections to a HTTP POST
Synopsis
form:AddFiles(name, table)
Function
form:AddFiles() is used to append multiple file upload sections 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 get 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 table argument must contain a table describing a list of files to be added to the form post object. There must be one item per file in the table. The individual table items can be of three different types:

  1. a string: In that case, the string must simply contain the path to the file to be uploaded.
  2. a table with two strings: In that case, the first string must contain the path to the file to be uploaded and the second string must contain the content-type for the file.
  3. a table with three strings: Same as above, but the third string must contain a file name that should be used for the part instead of the file name derived from the path specified in the first string in the table

Inputs
name
name of the part
table
table containing the files to be uploaded (see above)

Show TOC