field({| name: String, value: Any, mime?: String, fileName?: String |}): MultipartPart
Creates a MultipartPart data structure using the specified part name,
input content for the part, format (or mime type), and optionally, file name.
This version of the field function accepts arguments as an array of objects
that use the parameter names as keys, for example:
Multipart::field({name:"order",value: myOrder, mime: "application/json", fileName: "order.json"})
Parameters
| Name | Description |
|---|---|
|
Array of objects that specifies:
|
Example
This example produces two parts. The first part (named order) outputs
content in JSON and provides a file name for the part (order.json). The
second (named clients) outputs content in XML and does not provide a file
name. Also notice that in this example you need to add the function’s
namespace to the function name, for example, Multipart::field.
Source
%dw 2.0
import dw::module::Multipart
output multipart/form-data
var myOrder = [
{
order: 1,
amount: 2
},
{
order: 32,
amount: 1
}
]
var myClients = {
clients: {
client: {
id: 1,
name: "Mariano"
},
client: {
id: 2,
name: "Shoki"
}
}
}
---
{
parts: {
order: Multipart::field({name:"order",value: myOrder, mime: "application/json", fileName: "order.json"}),
clients: Multipart::field({name:"clients", value: myClients, mime: "application/xml"})
}
}
Output
------=_Part_8032_681891620.1542560124825
Content-Type: application/json
Content-Disposition: form-data; name="order"; filename="order.json"
[
{
"order": 1,
"amount": 2
},
{
"order": 32,
"amount": 1
}
]
------=_Part_8032_681891620.1542560124825
Content-Type: application/xml
Content-Disposition: form-data; name="clients"
<clients>
<client>
<id>1</id>
<name>Mariano</name>
</client>
<client>
<id>2</id>
<name>Shoki</name>
</client>
</clients>
------=_Part_8032_681891620.1542560124825--
field(String, Any, String, String): MultipartPart
Creates a MultipartPart data structure using the specified part name,
input content for the part, format (or mime type), and optionally, file name.
This version of the field function accepts arguments in a comma-separated
list, for example:
Multipart::field("order", myOrder,"application/json", "order.json")`
Parameters
| Name | Description |
|---|---|
|
A set of parameters that specify:
|
Example
This example produces two parts. The first part (named order) outputs
content in JSON and provides a file name for the part (order.json). The
second (named clients) outputs content in XML and does not provide a file
name. The only difference between this field example and the previous
field example is the way you pass in arguments to the method. Also notice
that in this example you need to add the function’s namespace to the function
name, for example, Multipart::field.
Source
%dw 2.0
import dw::module::Multipart
output multipart/form-data
var myOrder = [
{
order: 1,
amount: 2
},
{
order: 32,
amount: 1
}
]
var myClients = {
clients: {
client: {
id: 1,
name: "Mariano"
},
client: {
id: 2,
name: "Shoki"
}
}
}
---
{
parts: {
order: Multipart::field("order", myOrder, "application/json", "order.json"),
clients: Multipart::field("clients", myClients, "application/xml")
}
}
Output
------=_Part_4846_2022598837.1542560230901
Content-Type: application/json
Content-Disposition: form-data; name="order"; filename="order.json"
[
{
"order": 1,
"amount": 2
},
{
"order": 32,
"amount": 1
}
]
------=_Part_4846_2022598837.1542560230901
Content-Type: application/xml
Content-Disposition: form-data; name="clients"
<clients>
<client>
<id>1</id>
<name>Mariano</name>
</client>
<client>
<id>2</id>
<name>Shoki</name>
</client>
</clients>
------=_Part_4846_2022598837.1542560230901--