---
schema_version: "1"
id: 824b4aec937f0d0171dc21e48307bd1af62479dfa6e52387e17ed234171f4472
title: マルチパート形式 (フォームデータ)
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/dataweave/2.3/dataweave-formats-multipart.md
canonical_url: https://docs.mulesoft.com/jp/dataweave/2.3/dataweave-formats-multipart
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 204862c8848cfe1990c202168175022f75fb61cea883e77c675c9ef126607f78
description: MuleSoft Documentation Site
release: "2.3"
latest: false
---
# マルチパート形式 (フォームデータ)

MIME タイプ: `multipart/form-data`​

ID: `multipart`​

DataWeave ではマルチパートサブタイプ (特に ​`form-data`​) がサポートされます。この形式では、各パートの形式に関係なく、1 つのペイロード内で複数の異なるデータパートを処理できます。パートの開始と終了を区別するには、境界を使用します。各パートのメタデータはヘッダーを介して追加できます。

DataWeave では、特定の ​`Object`​ 構造を使用して、マルチパートドキュメントを表します。

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

## [](#examples)例

次の例は、マルチパート形式の使用方法を示しています。

- [例: マルチパート](#example1)​
- [例: パートのデータにアクセスして変換する](#example2)​
- [例: マルチパートコンテンツを生成する](#example3)

### [](#example1)例: マルチパート

次の例は、DataWeave で単純なマルチパートコンテンツを読み取る方法を示しています。

#### [](#入力)入力

マルチパート入力は、DataWeave ソースへのペイロードとして機能します。

```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--
```

#### [](#ソース)ソース

この DataWeave スクリプトは、マルチパート入力ペイロードを DataWeave (dw) 形式に変換します。

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

#### [](#出力)出力

この出力は、DataWeave (dw) 形式でマルチパート入力がどのように表されるのかを示しています。​`raw`​ および ​`content`​ 値は、簡潔にするために短縮されています。完全な値はこれよりも長くなります。

```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"
            }
       }
    }
}
```

### [](#example2)例: パートのデータにアクセスして変換する

DataWeave スクリプト内で、​`parts`​ 要素を選択し、任意のパートのデータにアクセスし、変換できます。操作は配列に基づくことができます。また、パートを参照するための名前がパートに設定されている場合は、キーに基づくことができます。パートのデータには ​`content`​ キーワードを介してアクセスでき、ヘッダーには ​`headers`​ キーワードを介してアクセスできます。

#### [](#入力-2)入力

次の例は、個別の DataWeave スクリプトへの入力として機能します。 3 つのパートで構成される ​`34b21`​ 境界を含む未加工の ​`multipart/form-data`​ ペイロードを以下に示します。

- `text`​ という名前の ​`text/plain`​
- `file1`​ という名前の ​`application/json`​ ファイル (​`a.json`​)
- `file2`​ という名前の ​`text/html`​ ファイル (​`a.html`​)

未加工のマルチパートデータ:

```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--
```

#### [](#ソース-2)ソース

次の DataWeave スクリプトは、入力として未加工の ​`multipart/form-data`​ ペイロードを使用し、​`Book:a.json`​ を生成します。

マルチパートコンテンツの読み取り:

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

### [](#example3)例: マルチパートコンテンツを生成する

DataWeave がパートのリスト (各パートにヘッダーとコンテンツが含まれる) を含むオブジェクトを構築するマルチパートコンテンツを生成できます。次の DataWeave スクリプトでは、ペイロード内で HTML データを使用できる場合に、(以前に分析した) 未加工のマルチパートデータを生成します。

マルチパートコンテンツの書き込み:

```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
    }
  }
}
```

パートの名前が ​`Content-Disposition`​ ヘッダーに明示的に提供されていない場合は、キーによりパートの名前が決まります。また、DataWeave は、サポートされる形式からのコンテンツを処理できるだけでなく、HTML など、サポートされない形式への参照からコンテンツを処理できます。

## [](#properties)Configuration のプロパティ

DataWeave では、マルチパート形式の次の設定プロパティがサポートされています。

### [](#reader-のプロパティ)Reader のプロパティ

マルチパート形式では、入力データの読み込みの指示を提供するプロパティを使用できます。

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 16.6666%;">
<col style="width: 16.6666%;">
<col style="width: 16.6666%;">
<col style="width: 50.0002%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">パラメーター</th>
<th class="tableblock halign-left valign-top">型</th>
<th class="tableblock halign-left valign-top">デフォルト</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>boundary</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>String</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>null</code></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>マルチパートの ​<code>boundary</code>​ 値。パートを区切る文字列。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>defaultContentType</code>​</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>String</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">このプロパティにデフォルト値はありません。</p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>​<code>multipart/*</code>​ 形式のパートで使用するデフォルトのコンテンツタイプを設定します。設定すると、このプロパティは ​<code>com.mulesoft.dw.multipart.defaultContentType</code>​ の <a href="https://docs.mulesoft.com/mule-runtime/4.3/dataweave-system-properties">システムプロパティ設定</a>​よりも優先されます。​<em>2021 年 8 月リリースの Mule 4.3.0-20210719 の DataWeave 2.3 (2.3.0-20210720) で導入されました。</em>​</p>
</div></div></td>
</tr>
</tbody>
</table>

### [](#writer-のプロパティ)Writer のプロパティ

マルチパート形式では、出力データの書き込みの指示を提供するプロパティを使用できます。

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 16.6666%;">
<col style="width: 16.6666%;">
<col style="width: 16.6666%;">
<col style="width: 50.0002%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">パラメーター</th>
<th class="tableblock halign-left valign-top">型</th>
<th class="tableblock halign-left valign-top">デフォルト</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>boundary</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>String</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>null</code></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>マルチパートの境界値。パートを区切る文字列。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>bufferSize</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>Number</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>8192</code></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>バッファライターのサイズ。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>deferred</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>Boolean</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>false</code></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>​<code>true</code>​ に設定すると、DataWeave は出力をデータストリームとして生成し、スクリプトの実行はそれがコンシュームされるまで延期されます。
  有効な値は、​<code>true</code>​ または ​<code>false</code>​ です。</p>
</div></div></td>
</tr>
</tbody>
</table>

## [](#mime_type)サポートされる MIME タイプ (マルチパート)

マルチパート形式では、次の MIME タイプがサポートされています。

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 100%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">MIME タイプ</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>multipart/*</code>​</p></td>
</tr>
</tbody>
</table>