Builds a multipart form body for use with XMLHttpRequest.send(), mirroring the browser FormData API for app scripts that need to post multipart/form-data content. Values can be appended as plain strings, byte arrays, input streams, uploaded file items, or Kademi content resources, each becoming its own named part. An instance is constructed with a plain 'new FormData()' from script code, populated with append(), and then passed to XMLHttpRequest.send() to populate the outgoing request body.
Methods
append(String name, String value) · append(String name, InputStream in) · append(String name, InputStream in, String fileName) · append(String name, FileItem fileItem) · append(String name, FileItem fileItem, String fileName) · append(String name, AbstractContentResource acr) · append(String name, AbstractContentResource fr, String fileName) · append(String name, FileNode fileNode) · append(String name, FileNode fileNode, String fileName) · append(String name, byte[] bytes) · append(String name, byte[] bytes, String fileName) · delete(String name) · has(String name)
append(String name, String value)
Returns: void
Appends a plain text part to the form body under the given field name. Multiple values can be appended under the same name; each becomes a separate part.
| Parameter | Description |
|---|---|
name | the field name of the part |
value | the text value of the part |
append(String name, InputStream in)
Returns: void
Appends the full contents of a stream as a part with no file name, reading it into memory. Equivalent to calling append(name, in, null).
| Parameter | Description |
|---|---|
name | the field name of the part |
in | the stream to read the part content from; it is read fully but not closed |
append(String name, InputStream in, String fileName)
Returns: void
Appends the full contents of a stream as a file part, reading it into memory and deriving the content type from the given file name.
| Parameter | Description |
|---|---|
name | the field name of the part |
in | the stream to read the part content from; it is read fully but not closed |
fileName | the file name recorded on the part, used to work out its content type |
append(String name, FileItem fileItem)
Returns: void
Appends an uploaded file item as a part, using its own content type and file name.
| Parameter | Description |
|---|---|
name | the field name of the part |
fileItem | the uploaded file item to read the part content, content type and file name from |
append(String name, FileItem fileItem, String fileName)
Returns: void
Appends an uploaded file item as a part, using its own content type but overriding the file name recorded on the part.
| Parameter | Description |
|---|---|
name | the field name of the part |
fileItem | the uploaded file item to read the part content and content type from |
fileName | the file name to record on the part, in place of the file item's own name |
append(String name, AbstractContentResource acr)
Returns: void
Appends a Kademi content resource as a file part, using its own name as the part's file name. Equivalent to calling append(name, acr, acr.getName()).
| Parameter | Description |
|---|---|
name | the field name of the part |
acr | the content resource whose content is sent and whose name is used as the file name |
append(String name, AbstractContentResource fr, String fileName)
Returns: void
Appends a Kademi content resource as a file part, overriding the file name recorded on the part. The resource's content is read fully into memory before being added.
| Parameter | Description |
|---|---|
name | the field name of the part |
fr | the content resource whose content is sent |
fileName | the file name to record on the part |
append(String name, FileNode fileNode)
Returns: void
Appends a VFS file node as a file part, using its own name as the part's file name. Equivalent to calling append(name, fileNode, fileNode.getName()).
| Parameter | Description |
|---|---|
name | the field name of the part |
fileNode | the file node whose content is sent and whose name is used as the file name |
append(String name, FileNode fileNode, String fileName)
Returns: void
Appends a VFS file node as a file part, overriding the file name recorded on the part.
| Parameter | Description |
|---|---|
name | the field name of the part |
fileNode | the file node whose content is sent |
fileName | the file name to record on the part |
append(String name, byte[] bytes)
Returns: void
Appends a raw byte array as a part with no file name. Equivalent to calling append(name, bytes, null).
| Parameter | Description |
|---|---|
name | the field name of the part |
bytes | the raw content of the part |
append(String name, byte[] bytes, String fileName)
Returns: void
Appends a raw byte array as a part, working out its content type from the given file name when one is supplied. This is the method every other append() overload ultimately delegates to.
| Parameter | Description |
|---|---|
name | the field name of the part |
bytes | the raw content of the part |
fileName | the file name recorded on the part and used to derive its content type, or null for a plain text part with no content type |
delete(String name)
Returns: void
Removes all parts previously appended under the given field name, if any exist.
| Parameter | Description |
|---|---|
name | the field name to remove |
has(String name)
Returns: boolean
Checks whether at least one part has been appended under the given field name.
| Parameter | Description |
|---|---|
name | the field name to check |