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

# file

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

## 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:

```txt
Multipart::file({ name: "myFile", path: "myClients.json", mime: "application/json", fileName: "partMyClients.json"})
```

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>opts</code></p></td><td><div><div><p>Array of objects that specifies:</p></div><div><ul><li><p>A unique <code>name</code> (required) for the <code>Content-Disposition</code> header of the part.</p></li><li><p>A <code>path</code> (required) relative to the <code>src/main/resources</code> project path for the Mule app.</p></li><li><p><code>mime</code> (optional for strings) for the mime type (for example, <code>application/json</code>) to apply to content within the part. This setting <em>cannot</em> be used to transform the input mime type.</p></li><li><p>An optional <code>fileName</code> value for the <code>filename</code> parameter in the part’s <code>Content-Disposition</code> header. Defaults to the string <code>"filename"</code> if not supplied. This value does not need to match the input file name.</p></li></ul></div></div></td></tr></tbody></table>

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

```DataWeave
%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)
])
```

#### Input

A file called `myClients.json` and located in `src/main/resources` with the following content.

```json
clients: {
  client: {
    id: 1,
     name: "Mariano"
   },
   client: {
     id: 2,
     name: "Shoki"
  }
}
```

#### Output

```txt
------=_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--
```

## 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:

```txt
Multipart::field("myFile", myClients, 'application/json', "partMyClients.json")
```

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>opts</code></p></td><td><div><div><p>Array of objects that specifies:</p></div><div><ul><li><p>A unique <code>name</code> (required) for the <code>Content-Disposition</code> header of the part.</p></li><li><p>A <code>path</code> (required) relative to the <code>src/main/resources</code> project path for the Mule app.</p></li><li><p><code>mime</code> (optional for strings) for the mime type (for example, <code>application/json</code>) to apply to content within the part. This setting <em>cannot</em> be used to transform the input mime type.</p></li><li><p>An optional <code>fileName</code> value for the <code>filename</code> parameter in the part’s <code>Content-Disposition</code> header. Defaults to the string <code>"filename"</code> if not supplied. This value does not need to match the input file name.</p></li></ul></div></div></td></tr></tbody></table>

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

```DataWeave
%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")
])
```

#### Input

A file called `myClients.json` and located in `src/main/resources` with the following content.

```JSON
clients: {
    client: {
      id: 1,
      name: "Mariano"
    },
    client: {
      id: 2,
      name: "Shoki"
    }
  }
```

#### Output

```txt
------=_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--
```
