Class: RequestBody

RequestBody

new RequestBody(fields, boundary, callback)

Represents a multipart message body to be serialized.

Parameters:
Name Type Argument Default Description
fields Object | Array

A key-value Object map of fields to append

boundary String <optional>
random

Override the default MIME part boundary

callback String <optional>

If set, invoked after appending fields

Source:

Members

<private> availableTypes

Source:

Methods

append(fields, replace) → {this}

Append one or more fields to the RequestBody. If a fields is a string, this method acts as an alias of module:maltypart.RequestBody#setField.

Parameters:
Name Type Argument Default Description
fields Array | Object

An Array of objects with name and value properties, or a key-value Object.

replace Boolean <optional>
true

By default, any existing field with the same name is replaced. If replace is set to false, existing values will be left in-place, and the new value will be appended. This results in duplicate keys (which can be useful!).

Source:
Returns:
Type
this

getContentType(includeCharset) → {String}

Returns the appropriate Content-Type header value for this request body.

Parameters:
Name Type Argument Default Description
includeCharset Boolean <optional>
false

If true, specifies a character set within the content-type.

Source:
Returns:

contentType

Type
String

getData() → {String|Uint8Array}

Get the String or Uint8Array multipart request body.

Source:
Returns:

data

Type
String | Uint8Array

getType() → {String}

Returns a String indicating if the RequestBody will be serialized as multipart, or form-encoded. If no fields have been added that have a contentType, the request will be serialized as form-encoded.

Source:
Returns:

type

Type
String

setBoundary(boundary) → {this}

Set a custom "boundary" String to use when separating multipart fields.

Parameters:
Name Type Argument Default Description
boundary String <optional>
rnd()

A custom boundary. If omitted, generates a new random boundary.

Source:
Returns:
Type
this

setField(name, value, replace, headers) → {this}

Set the value of a new or existing field.

Parameters:
Name Type Argument Default Description
name String

A field name with which to associate the specified value

value String | module:maltypart.RequestField | Element | File

Any of: a RequestField, a simple String value, an HTML5 File object, or any form input Element.

replace Boolean <optional>
true

By default, any existing field with the same name is replaced. If replace is set to false, existing values will be left in-place, and the new value will be appended. This results in duplicate keys (which can be useful!).

headers Object <optional>

If set, headers will be added to the field

Source:
Returns:
Type
this

setFileField(name, file, callback) → {this}

Add an HTML5 File object to the request body

Parameters:
Name Type Argument Description
name String

A field name with which to associate the acquired field value

file File

An HTML5 File object.

callback function <optional>

A callback to call once the file has been fully added.

Source:
Returns:
Type
this

setType(type) → {this}

Override the automatic mutlipart/form-encoded detection.

Parameters:
Name Type Description
type String

One of: multipart or form-encoded.

Source:
Returns:
Type
this

toString(fields) → {String}

Get the request body as a String.

Parameters:
Name Type Argument Description
fields Object <optional>

Optionally add fields prior to serialization

Source:
Returns:

encodedMultipartBody

Type
String
Menu