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 |
- Source:
Members
-
<private> availableTypes
-
- Source:
Methods
-
append(fields, replace) → {this}
-
Append one or more fields to the RequestBody. If a
fieldsis astring, this method acts as an alias of module:maltypart.RequestBody#setField.Parameters:
Name Type Argument Default Description fieldsArray | Object An Array of objects with
nameandvalueproperties, or a key-value Object.replaceBoolean <optional>
true By default, any existing field with the same name is replaced. If
replaceis set tofalse, 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 includeCharsetBoolean <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
Stringindicating if the RequestBody will be serialized asmultipart, orform-encoded. If no fields have been added that have acontentType, the request will be serialized asform-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 boundaryString <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 nameString A field name with which to associate the specified value
valueString | module:maltypart.RequestField | Element | File Any of: a RequestField, a simple String value, an HTML5 File object, or any form input Element.
replaceBoolean <optional>
true By default, any existing field with the same name is replaced. If
replaceis set tofalse, existing values will be left in-place, and the new value will be appended. This results in duplicate keys (which can be useful!).headersObject <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 nameString A field name with which to associate the acquired field value
fileFile An HTML5 File object.
callbackfunction <optional>
A callback to call once the file has been fully added.
- Source:
Returns:
- Type
- this
-
setType(type) → {this}
-
Override the automatic
mutlipart/form-encodeddetection.Parameters:
Name Type Description typeString One of:
multipartorform-encoded.- Source:
Returns:
- Type
- this
-
toString(fields) → {String}
-
Get the request body as a String.
Parameters:
Name Type Argument Description fieldsObject <optional>
Optionally add fields prior to serialization
- Source:
Returns:
encodedMultipartBody
- Type
- String