---
schema_version: "1"
id: 0341b8f696423251bd2df31a495e5c05622f46227f23a8bbead60afc374bf8b3
title: form
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.6/dw-multipart-functions-form.md
canonical_url: https://docs.mulesoft.com/dataweave/2.6/dw-multipart-functions-form
source_site: docs.mulesoft.com
content_type: documentation
content_hash: ad6110a699e2cbd8efbc2aeaa84bdda7b72a9087f4450f28ec16c82bca941125
description: MuleSoft Documentation Site
release: "2.6"
latest: false
---
---
product: DataWeave
version: 2.6
---

# form

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## form(parts: Array<MultipartPart>): Multipart

Creates a `Multipart` data structure using a specified array of parts.

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>parts</code></p></td><td><div><div><p>An array of parts (<code>MultipartPart</code> data structures).</p></div></div></td></tr></tbody></table>

### Example

This example creates a `Multipart` data structure that contains three parts.

The first part uses the `Multipart::file()` function to import an external file named `orders.xml`.
The file is located in the internal `src/main/resources` folder of the Mule application. See the
[file](https://docs.mulesoft.com/dataweave/2.6/dw-multipart-functions-file) function documentation for more details on this example.

The second part uses the `Multipart::field()` function version that accepts field names as input
parameters in the form of an object with key/value pairs, enabling you to pass the keys in any
order. This part also does not specify the optional `fileName` parameter. When specified, `fileName`
is part of the `Content-Distribution` element of the part. The `mime` field is also optional. When
included, the field sets the `Content-Type` element to the `mime` value. In this case the
`Content-Type` is set to `text/plain`.

The third part uses the more compact version of the `Multipart::field()` function which sets the
required and optional parameters, in the correct order, as input parameters. The first three
parameters `name`, `value`, and `mime` are required. The `fileName` parameters is optional, use it
only if the content is read from a file or is written to a file. In this version, the `mime`
parameter is output as the `Content-Type` element, and the `fileName` is output as the `filename`
parameter of the `Content-Distribution` element.

#### Source

```DataWeave
%dw 2.0
import dw::module::Multipart
output multipart/form-data
var myOrders = "./orders.xml"
var fileArgs = { name: "file", path: myOrders, mime: "application/xml", fileName: "myorders.xml"}
var fieldArgs = {name:"userName",value: "Annie Point", mime: "text/plain"}
---
Multipart::form([
  Multipart::file(fileArgs),
  Multipart::field(fieldArgs),
  Multipart::field("myJson", {"user": "Annie Point"}, "application/json", "userInfo.json")
])
```

#### Output

```json
------=_Part_146_143704079.1560394078604
Content-Type: application/xml
Content-Disposition: form-data; name="file"; filename="myorders.xml"
<?xml version='1.0' encoding='UTF-8'?>
<orders>
  <order>
    <item>
      <id>1001</id>
      <qty>1</qty>
      <price>$100</price>
    </item>
    <item>
      <id>2001</id>
      <qty>2</qty>
      <price>$50</price>
    </item>
  </order>
</orders>
------=_Part_146_143704079.1560394078604
Content-Type: text/plain
Content-Disposition: form-data; name="userName"
Annie Point
------=_Part_146_143704079.1560394078604
Content-Type: application/json
Content-Disposition: form-data; name="myJson"; filename="userInfo.json"
{
  "user": "Annie Point"
}
------=_Part_146_143704079.1560394078604--
```

### Example

This example constructs a data structure using DataWeave code that is compatible with the
`multipart/form-data` output format, demonstrating how you can manually construct a data structure
compatible with `multipart/form-data` output, without using the `form` function.

In the following structure, the part keys `part1` and `part2` are stripped out in the
`multipart/form-data` output.

#### Source

```DataWeave
%dw 2.0
import dw::module::Multipart
output multipart/form-data
var firstPart = "content for my first part"
var secondPart = "content for my second part"
---
{
  parts: {
    part1: Multipart::field({name:"myFirstPart",value: firstPart}),
    part2: Multipart::field("mySecondPart", secondPart)
  }
}
```

#### Output

```txt
------=_Part_320_1528378161.1542639222352
Content-Disposition: form-data; name="myFirstPart"

content for my first part
------=_Part_320_1528378161.1542639222352
Content-Disposition: form-data; name="mySecondPart"

content for my second part
------=_Part_320_1528378161.1542639222352--
```
