Skip to content

libcURL.MultipartForm.AddElement

Andrew Lambert edited this page Jan 14, 2023 · 30 revisions

Method Signatures

 Sub AddElement(Name As String, Value As String, AdditionalHeaders As libcURL.ListPtr = Nil)
 Sub AddElement(Name As String, Value As FolderItem, ContentType As String = "", AdditionalHeaders As libcURL.ListPtr = Nil)
 Sub AddElement(Name As String, ValueStream As Readable, ValueSize As Integer, Filename As String = "", ContentType As String = "", AdditionalHeaders As libcURL.ListPtr = Nil)
 Sub AddElement(Name As String, ByRef Value As MemoryBlock, Filename As String, ContentType As String = "", AdditionalHeaders As libcURL.ListPtr = Nil)
 Sub AddElement(Name As String, Values() As FolderItem)

Parameters

AddElement(String, String, libcURL.ListPtr)

Name Type Comment
Name String The name of the form element (i.e. the name attribute of the HTML <input> tag)
Value String The content of the element
AdditionalHeaders ListPtr Optional. Additional MIME headers to include in the element.

AddElement(String, FolderItem, String, libcURL.ListPtr)

Name Type Comment
Name String The name of the form element (i.e. the name attribute of the HTML <input> tag)
Value FolderItem The file to encode in the form
ContentType String Optional. The Content-Type of the file (e.g. text/html.)
AdditionalHeaders ListPtr Optional. Additional MIME headers to include in the element.

AddElement(String, Readable, Integer, String, String, libcURL.ListPtr)

Name Type Comment
Name String The name of the form element (i.e. the name attribute of the HTML <input> tag)
ValueStream Readable The stream from which to read the contents of the form element when they are actually needed.
ValueSize Integer The total number of bytes to read from ValueStream. Pass 0 to read until ValueStream.EOF
Filename String Optional. If specified then the form element is encoded as a file element.
ContentType String Optional. The Content-Type of the file (e.g. text/html.) This parameter is ignored if Filename is not specified.
AdditionalHeaders ListPtr Optional. Additional MIME headers to include in the element.

AddElement(String, ByRef MemoryBlock, String, String, libcURL.ListPtr)

Name Type Comment
Name String The name of the form element (i.e. the name attribute of the HTML <input> tag)
Value MemoryBlock A pointer to a memory block containing the value. Must remain valid for the duration of all transfers.
Filename String The file name to use. While not an optional parameter, you may pass the empty string if the element should not be encoded as a file element.
ContentType String Optional. The Content-Type of the file (e.g. text/html.) This parameter is ignored if Filename is the empty string.
AdditionalHeaders ListPtr Optional. Additional MIME headers to include in the element.

AddElement(String, FolderItem())

Name Type Comment
Name String The name of the form element (i.e. the name attribute of the HTML <input> tag)
Values FolderItem array An array of FolderItems which will be encoded as a nested form.

Remarks

Pass a string to set a string element or a folderitem to set a file upload element. You may also pass a Readable object to have libcURL read from when the form element contents are needed, a pointer to a memory buffer that already contains file data, or an array of FolderItems to be encoded as MIME attachments in a nested form.

You may add custom MIME headers in the form element by specifying the AdditionalHeaders parameter.

Example

This example POSTs an HTTP form containing a string part, a file part with additional MIME headers, a MemoryBlock part, and a Readable part:

  Dim form As New libcURL.MultipartForm
  form.AddElement("Username", "Bob")
  
  Dim mimeheaders As New libcURL.ListPtr
  mimeheaders.Append("X-Custom-Header: CustomValue")
  Dim file As FolderItem = GetOpenFolderItem("")
  form.AddElement("Upload", file, "", mimeheaders)
  
  Dim testdata As MemoryBlock = "This is a test buffer."
  form.AddElement("Buffer", testdata, "buffer.txt", "text/plain")
  
  Dim stream As New BinaryStream(testdata)
  form.AddElement("Stream", stream, stream.Length)
  
  Dim c As New cURLClient
  If c.Post("http://www.example.com/submit.php", form) Then
    MsgBox("Success!")
  End If

See also

Clone this wiki locally