Multipart::file({ name: "myFile", path: "myClients.json", mime: "application/json", fileName: "partMyClients.json"})txt
file
file({| name: String, path: String, mime?: String, fileName?: String |})
Creates a MultipartPart data structure from a resource file.
This version of the file function accepts arguments as an array of objects
that use the parameter names as keys, for example:
Parameters
| Name | Description |
|---|---|
|
Array of objects that specifies:
|
Example
This example inserts file content from a MultipartPart into a Multipart
data structure. It uses the form function to create the Multipart
and uses file to create a part named myClient with JSON content from
an external file myClients.json. It also specifies partMyClients.json as
the value for to the filename parameter.
Source
%dw 2.0
import dw::module::Multipart
output multipart/form-data
var myClients = "myClients.json"
var myArgs = { name: "myFile", path: "myClients.json", mime: "application/json", * fileName: "partMyClients.json"}
---
Multipart::form([
Multipart::file(myArgs)
])DataWeave
Input
A file called myClients.json and located in src/main/resources with the
following content.
clients: {
client: {
id: 1,
name: "Mariano"
},
client: {
id: 2,
name: "Shoki"
}
}json
Output
------=_Part_1586_1887987980.1542569342438 Content-Type: application/json Content-Disposition: form-data; name="myFile"; filename="partMyClients.json" { clients: { client: { id: 1, name: "Mariano" }, client: { id: 2, name: "Shoki" } } } ------=_Part_1586_1887987980.1542569342438--txt
file(String, String, String, String)
Creates a MultipartPart data structure from a resource file.
This version of the file function accepts arguments in a comma-separated
list, for example:
Multipart::field("myFile", myClients, 'application/json', "partMyClients.json")txt
Parameters
| Name | Description |
|---|---|
|
Array of objects that specifies:
|
Example
This example inserts file content from a MultipartPart into a Multipart
data structure. It uses the form function to create the Multipart type
and uses file to create a part named myClient with JSON content from
an external file myClients.json. It also specifies partMyClients.json as
the value for to the filename parameter.
Source
%dw 2.0
import dw::module::Multipart
var myClients = "myClients.json"
output multipart/form-data
---
Multipart::form([
Multipart::file("myFile", myClients, 'application/json', "partMyClients.json")
])DataWeave
Input
A file called myClients.json and located in src/main/resources with the
following content.
clients: {
client: {
id: 1,
name: "Mariano"
},
client: {
id: 2,
name: "Shoki"
}
}JSON
Output
------=_Part_1586_1887987980.1542569342438 Content-Type: application/json Content-Disposition: form-data; name="myFile"; filename="partMyClients.json" { clients: { client: { id: 1, name: "Mariano" }, client: { id: 2, name: "Shoki" } } } ------=_Part_1586_1887987980.1542569342438--txt



