# MultipartBody

The base class for all classes which can be used as `MultipartUserData`.

Obtainable from: MultipartBody.fromRawBody, MultipartBody.fromUserData
Used as argument in: [MultipartUserData.addPart](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.MultipartUserData.html#addpart)

- Source: [`aws-ec2/lib/user-data.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-ec2/lib/user-data.ts#L342)

## Example

TypeScript:

```ts
const multipartUserData = new ec2.MultipartUserData();
const commandsUserData = ec2.UserData.forLinux();
multipartUserData.addUserDataPart(commandsUserData, ec2.MultipartBody.SHELL_SCRIPT, true);

// Adding commands to the multipartUserData adds them to commandsUserData, and vice-versa.
multipartUserData.addCommands('touch /root/multi.txt');
commandsUserData.addCommands('touch /root/userdata.txt');
```

Python:

```python
multipart_user_data = ec2.MultipartUserData()
commands_user_data = ec2.UserData.for_linux()
multipart_user_data.add_user_data_part(commands_user_data, ec2.MultipartBody.SHELL_SCRIPT, True)

# Adding commands to the multipartUserData adds them to commandsUserData, and vice-versa.
multipart_user_data.add_commands("touch /root/multi.txt")
commands_user_data.add_commands("touch /root/userdata.txt")
```

Java:

```java
MultipartUserData multipartUserData = new MultipartUserData();
UserData commandsUserData = UserData.forLinux();
multipartUserData.addUserDataPart(commandsUserData, MultipartBody.SHELL_SCRIPT, true);

// Adding commands to the multipartUserData adds them to commandsUserData, and vice-versa.
multipartUserData.addCommands("touch /root/multi.txt");
commandsUserData.addCommands("touch /root/userdata.txt");
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
var multipartUserData = new MultipartUserData();
var commandsUserData = UserData.ForLinux();
multipartUserData.AddUserDataPart(commandsUserData, MultipartBody.SHELL_SCRIPT, true);

// Adding commands to the multipartUserData adds them to commandsUserData, and vice-versa.
multipartUserData.AddCommands("touch /root/multi.txt");
commandsUserData.AddCommands("touch /root/userdata.txt");
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
multipartUserData := ec2.NewMultipartUserData()
commandsUserData := ec2.UserData_ForLinux()
multipartUserData.AddUserDataPart(commandsUserData, ec2.MultipartBody_SHELL_SCRIPT(), jsii.Boolean(true))

// Adding commands to the multipartUserData adds them to commandsUserData, and vice-versa.
multipartUserData.AddCommands(jsii.String("touch /root/multi.txt"))
commandsUserData.AddCommands(jsii.String("touch /root/userdata.txt"))
```

## Initializer

TypeScript:

```ts
new MultipartBody()
```

Python:

```python
MultipartBody()
```

Java:

```java
new MultipartBody()
```

C# / .NET:

```csharp
new MultipartBody()
```

Golang:

```go
NewMultipartBody()
```

## Properties

- `CLOUD_BOOTHOOK`: string (static) — Content type for boot hooks.

- `SHELL_SCRIPT`: string (static) — Content type for shell scripts.

## Methods

- `fromRawBody(opts: MultipartBodyOptions): MultipartBody // chainable` (static) — Constructs the raw `MultipartBody` using specified body, content type and transfer encoding.

  When transfer encoding is specified (typically as Base64), it's caller responsibility to convert body to
  Base64 either by wrapping with `Fn.base64` or by converting it by other converters.

- `fromUserData(userData: UserData, contentType?: string): MultipartBody // chainable` (static) — Constructs the new `MultipartBody` wrapping existing `UserData`. Modification to `UserData` are reflected in subsequent renders of the part.

  For more information about content types see `MultipartBodyOptions.contentType`.

  **Parameters**

  - `userData` — user data to wrap into body part.
  - `contentType` — optional content type, if default one should not be used.

- `renderBodyPart(): string[]` — Render body part as the string.

  Subclasses should not add leading nor trailing new line characters (\r \n)
