---
schema_version: "1"
id: 08321cc552ec2695239d6138225493fbf83ecac1bc82ffdd70dc5fa1f675c68d
title: Multipart Format (Form Data)
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.3/dataweave-formats-multipart.md
canonical_url: https://docs.mulesoft.com/dataweave/2.3/dataweave-formats-multipart
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 5f6a0146541f9a3073b0b7de33c51a3fc612a25f29900a5c6c644b1a8ca2ef8d
description: MuleSoft Documentation Site
release: "2.3"
latest: false
---
---
product: DataWeave
version: 2.3
---

# Multipart Format (Form Data)

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

MIME Type: `multipart/form-data`

ID: `multipart`

DataWeave supports Multipart subtypes, in particular `form-data`. These formats enable you to handle
several different data parts in a single payload, regardless of the format each part has. To
distinguish the beginning and end of a part, a boundary is used and metadata for each part can be
added through headers.

DataWeeave represents a Multipart document with the given `Object` structure:

```weave
type Multipart = {
  preamble?: String,
  parts: {
    _?: MultipartPart
  }
}
type MultipartPart = {
  headers?: {
    "Content-Disposition"?: {
      name: String,
      filename?: String
    },
    "Content-Type"?: String
  },
  content: Any
}
```

## Examples

The following examples show uses of the Multipart format.

- [Example: Multipart](#example1)

- [Example: Access and Transform Data from Parts](#example2)

- [Example: Generate Multipart Content](#example3)

### Example: Multipart

This example shows how DataWeave reads simple Multipart content.

#### Input

The Multipart input serves as the payload to the DataWeave source.

```text
--34b21
Content-Disposition: form-data; name="text"
Content-Type: text/plain

Book
--34b21
Content-Disposition: form-data; name="file1"; filename="a.json"
Content-Type: application/json

{
"title": "Java 8 in Action",
"author": "Mario Fusco",
"year": 2014
}
--34b21
Content-Disposition: form-data; name="file2"; filename="a.html"
Content-Type: text/html

<title> Available for download! </title>
--34b21--
```

#### Source

The DataWeave script transforms the Multipart input payload to the DataWeave (dw) format.

```weave
%dw 2.0
output application/dw
---
payload
```

#### Output

The output shows how the DataWeave (dw) format represents the Multipart input. Note that the `raw`
and `content` values are shortened for brevity. The full values are longer.

```weave
{
    parts: {
        text: {
            headers: {
                "Content-Disposition": {
                    name: "text",
                    subtype: "form-data"
                },
                "Content-Type": "text/plain"
            },
        content: "Book" as String {
            raw: "Qm9vaw==" as Binary {
                    base: "64"
                },
                encoding: null,
                mediaType: "text/plain",
                mimeType: "text/plain"
            }
        },
        file1: {
            headers: {
                "Content-Disposition": {
                    name: "file1",
                    filename: "a.json",
                    subtype: "form-data"
                },
                "Content-Type": "application/json"
            },
            content: {
                title: "Java 8 in Action",
                author: "Mario Fusco",
                year: 2014
            } as Object {
                raw: "ewogICJ0aXRsZSI6ICJKYXZhI...==" as Binary {
                    base: "64"
                },
                encoding: null,
                mediaType: "application/json",
                mimeType: "application/json"
            }
        },
        file2: {
            headers: {
                "Content-Disposition": {
                    name: "file2",
                    filename: "a.html",
                    subtype: "form-data"
                },
                "Content-Type": "text/html"
            },
            content: "PCFET0NUWVBFIGh0bWw+Cjx0aXRsZT4KI...==" as Binary {
                base: "64"
            }
       }
    }
}
```

### Example: Access and Transform Data from Parts

Within a DataWeave script, you can access and transform data from any of the parts by selecting the
`parts` element. Navigation can be array-based or key-based when parts feature a name to reference
them by. The part’s data can be accessed through the `content` keyword, while headers can be
accessed through the `headers` keyword.

#### Input

This example serves as input to separate DataWeave scripts. shows a raw `multipart/form-data`
payload with a `34b21` boundary consisting of 3 parts:

- a `text/plain` one named `text`

- an `application/json` file (`a.json`) named `file1`

- a `text/html` file (`a.html`) named `file2`

Raw Multipart Data:

```text
--34b21
Content-Disposition: form-data; name="text"
Content-Type: text/plain

Book
--34b21
Content-Disposition: form-data; name="file1"; filename="a.json"
Content-Type: application/json

{
  "title": "Java 8 in Action",
  "author": "Mario Fusco",
  "year": 2014
}
--34b21
Content-Disposition: form-data; name="file2"; filename="a.html"
Content-Type: text/html

<!DOCTYPE html>
<title>
  Available for download!
</title>
--34b21--
```

#### Source

The following DataWeave script uses the raw `multipart/form-data` payload as input to produce
`Book:a.json`.

Reading Multipart Content:

```dataweave
%dw 2.0
output text/plain
---
payload.parts.text.content ++ ':' ++ payload.parts[1].headers.'Content-Disposition'.filename
```

### Example: Generate Multipart Content

You can generate multipart content that DataWeave uses to build an object with a list of parts, each
containing its headers and content. The following DataWeave script produces the raw multipart data
(previously analyzed) if the HTML data is available in the payload.

Writing Multipart Content:

```dataweave
%dw 2.0
output multipart/form-data
boundary='34b21'
---
{
  parts : {
    text : {
      headers : {
        "Content-Type": "text/plain"
      },
      content : "Book"
    },
    file1 : {
      headers : {
        "Content-Disposition" : {
            "name": "file1",
            "filename": "a.json"
        },
        "Content-Type" : "application/json"
      },
      content : {
        title: "Java 8 in Action",
        author: "Mario Fusco",
        year: 2014
      }
    },
    file2 : {
      headers : {
        "Content-Disposition" : {
            "filename": "a.html"
        },
        "Content-Type" : payload.^mimeType
      },
      content : payload
    }
  }
}
```

Notice that the key determines the part’s name if the name is not explicitly provided in the
`Content-Disposition` header, and note that DataWeave can handle content from supported formats, as
well as references to unsupported ones, such as HTML.

## Configuration Properties

DataWeave supports the following configuration properties for the Multipart format.

### Reader Properties

The Multipart format accepts properties that provide instructions for reading input data.

<table><colgroup><col> <col> <col> <col></colgroup><thead><tr><th>Parameter</th><th>Type</th><th>Default</th><th>Description</th></tr></thead><tbody><tr><td><p><code>boundary</code></p></td><td><p><code>String</code></p></td><td><p><code>null</code></p></td><td><div><div><p>The multipart <code>boundary</code> value. A string to delimit parts.</p></div></div></td></tr><tr><td><p><code>defaultContentType</code></p></td><td><p><code>String</code></p></td><td><p>This property has no default value.</p></td><td><div><div><p>Sets the default Content-Type to use on parts of the <code>multipart/*</code> format. When set, this property takes precedence over the <a href="https://docs.mulesoft.com/dataweave/2.3/dataweave-system-properties">system property setting</a> for <code>com.mulesoft.dw.multipart.defaultContentType</code>. <em>Introduced in DataWeave 2.3 (2.3.0-20210720) for the August 2021 release of Mule 4.3.0-20210719.</em></p></div></div></td></tr></tbody></table>

### Writer Properties

The Multipart format accepts properties that provide instructions for writing output data.

<table><colgroup><col> <col> <col> <col></colgroup><thead><tr><th>Parameter</th><th>Type</th><th>Default</th><th>Description</th></tr></thead><tbody><tr><td><p><code>boundary</code></p></td><td><p><code>String</code></p></td><td><p><code>null</code></p></td><td><div><div><p>The multipart boundary value. A String to delimit parts.</p></div></div></td></tr><tr><td><p><code>bufferSize</code></p></td><td><p><code>Number</code></p></td><td><p><code>8192</code></p></td><td><div><div><p>Size of the buffer writer.</p></div></div></td></tr><tr><td><p><code>deferred</code></p></td><td><p><code>Boolean</code></p></td><td><p><code>false</code></p></td><td><div><div><p>When set to <code>true</code>, DataWeave generates the output as a data stream, and the script’s execution is deferred until it is consumed. Valid values are <code>true</code> or <code>false</code>.</p></div></div></td></tr></tbody></table>

## Supported MIME Types (for Multipart)

The Multipart format supports the following MIME types.

<table><colgroup><col></colgroup><thead><tr><th>MIME Type</th></tr></thead><tbody><tr><td><p><code>multipart/*</code></p></td></tr></tbody></table>
