# How to Send Binary File Data in Connector Request Body ?

**URL:** <https://forums.pega.com/t/how-to-send-binary-file-data-in-connector-request-body/9128>\
**Category:** Blueprint and App Design\
**Tags:** telephony, 8-8-5, blueprint, email, java-and-activities, chat-and-messaging, citizen-developer, cross-industry, case-management, generative-ai, pega-platform, senior-system-architect\
**Created:** [March 4, 2025, 1:31pm UTC](https://forums.pega.com/t/how-to-send-binary-file-data-in-connector-request-body/9128 "2025-03-04T13:31:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eranda\_Weerasingha](https://yyz2.discourse-cdn.com/pega/user_avatar/forums.pega.com/eranda_weerasingha/32/23633_2.png) [@Eranda\_Weerasingha](https://forums.pega.com/u/Eranda_Weerasingha)\
**Post date:** [March 4, 2025, 1:31pm UTC](https://forums.pega.com/t/how-to-send-binary-file-data-in-connector-request-body/9128/1 "2025-03-04T13:31:03Z")

</div>

Hi Team,

I have created a **Connector** rule in Pega, and I need to send a **binary file** as part of the **request body**. Additionally, I need to include the following headers in the request:

`Authorization: Bearer <AccessToken>`

`Content-Type: application/octet-stream`

I have also configured an **Authentication Profile** with **OAuth 2.0** and **Grant Type: Client Credentials** to generate the access token.

My questions are:

1. How can I properly pass the **binary file content** in the **request body**?
2. In the **Data Page** , I have added other request data in the **Request Data Transform**. How can I ensure the binary file data is also included correctly?
3. How can I confirm that the **Authorization header** is correctly passed when using the **Authentication Profile**?

Thank you,

Eranda.

---

<div class="post-metadata">

**Author:** ![MarijeSchillern](https://yyz2.discourse-cdn.com/pega/user_avatar/forums.pega.com/marijeschillern/32/23321_2.png) [@MarijeSchillern](https://forums.pega.com/u/MarijeSchillern)\
**Post date:** [March 24, 2025, 12:11pm UTC](https://forums.pega.com/t/how-to-send-binary-file-data-in-connector-request-body/9128/2 "2025-03-24T12:11:29Z")

</div>

@Eranda10274 ⚠ **This answer is by a GenAI-powered tool. All generated answers require validation against the provided references.**

Here’s a detailed breakdown for your implementation:

## **Sending Binary File Content in Request Body**

To properly pass binary file content in the request body, you’ll need to:

1. Configure your REST connector to use the `pyAttachValues` property, which is specifically designed for handling binary file content in Pega.
2. Base64-encode your binary content before sending it in the request. This is critical because Pega treats all multipart file content as binary, and assumes content is Base64-encoded when reading from or writing to the `pyAttachValues` property.
3. In your connector configuration, on the Methods tab:
  - Navigate to your HTTP method (POST/PUT)
  - Ensure the request is configured to map the binary content to the clipboard
  - In the Message data section, configure it to include the binary content

## **Setting Headers in the Request**

For your specified headers:

1. In your REST connector configuration, navigate to the Headers section.
2. Add your required headers:
  - Set the Content-Type header to `application/octet-stream` to indicate binary data
  - Set the Authorization header to `Bearer <AccessToken>`

3. For the Authorization header specifically, since you’re using OAuth 2.0 with Client Credentials:
  - The token will be automatically generated and used if you’ve configured the Authentication Profile correctly
  - Ensure the Authentication Profile is properly linked to your connector

## **Including Binary File Data with Data Page and Request Data Transform**

To ensure your binary file data is included correctly with the Data Page:

1. In your Data Page:
  - Configure it to return all necessary properties, including the `pyAttachValues` property that will contain your binary data
  - Make sure the Data Page is properly retrieving the binary content

2. In your Request Data Transform:
  - Ensure it maps all Data Page properties to the request body
  - Specifically include mapping for the `pyAttachValues` property to send the binary content correctly
  - Your existing request data should coexist with the binary data as long as both are properly mapped

3. The key properties for managing binary content are:
  - `pyAttachValues` - Holds the actual binary content (Base64-encoded)
  - `pyAttachNames` - Contains the content-disposition MIME header name values (if needed)
  - `pyAttachContentTypes` - Specifies the MIME type of each attachment (should include “application/octet-stream” for your use case)

## **Sample Implementation Approach**

Here’s a simplified example of how this might look in an activity:

```auto
// Retrieve or create the binary data

```

```auto
// (This could be from a file attachment, database blob, etc.)

```

```auto
Binary binaryData = ...;

```

```auto

 

```

```auto
// Create a page for the attachment data

```

```auto
Page attachmentPage = tools.createPage("Data-ServiceMessage", "");

```

```auto

 

```

```auto
// Convert binary to Base64

```

```auto
String base64Content = Base64.getEncoder().encodeToString(binaryData);

```

```auto

 

```

```auto
// Set the attachment values

```

```auto
attachmentPage.putString("pyAttachValues", base64Content);

```

```auto
attachmentPage.putString("pyAttachNames", "yourFileName.ext");

```

```auto
attachmentPage.putString("pyAttachContentTypes", "application/octet-stream");

```

```auto

 

```

```auto
// Set this as the request attachment page

```

```auto
tools.putPage("pyRequestAttachmentPage", attachmentPage);

```

```auto

 

```

```auto
// For explicit header setting if needed

```

```auto
tools.getRequest().addHeader("Content-Type", "application/octet-stream");

```

```auto
tools.getRequest().addHeader("Authorization", "Bearer " + accessToken);

```

References:

- [File attachment configuration in REST and SOAP integrations](https://docs.pega.com/bundle/platform-241/page/platform/data-integration/file-attachment-configuration-rest-soap-integrations.html)
- [Configuring a REST connector to receive binary attachments](https://docs.pega.com/bundle/platform-241/page/platform/data-integration/configuring-rest-connector-receive-binary-attachments.html)

---

<div class="post-metadata">

**Author:** ![Eranda\_Weerasingha](https://yyz2.discourse-cdn.com/pega/user_avatar/forums.pega.com/eranda_weerasingha/32/23633_2.png) [@Eranda\_Weerasingha](https://forums.pega.com/u/Eranda_Weerasingha)\
**Post date:** [March 24, 2025, 12:51pm UTC](https://forums.pega.com/t/how-to-send-binary-file-data-in-connector-request-body/9128/3 "2025-03-24T12:51:34Z")

</div>

Hi @MarijeSchillern, thank you for ansering my question, here is the one what found solution.

I have implemented the Base64 to binary conversion using the following approach:

```auto
add this code in the function

```

`byte[] bytes = Base64Util.decodeToByteArray(Base64BinaryContent); JavaObjectModeProperty.setValue(bytes)`

`(JavaObjectModeProperty is `ClipboardProperty and `Base64BinaryContent is string)`

This code converts Base64 format into binary and stores the value in the clipboard property.

Additionally, the authentication process will be handled within the **Authentication Profile** , including adding the Bearer `<token>`. To ensure correct functionality:

- The **Authentication Profile** must be properly configured.
- The **Connector Rule Requestor part** should be set to **Binary**.
- The previously stored **binary value property** must be used accordingly.

 ![add binary ss.png](https://pega1.discourse-cdn.com/pega/original/2X/1/10b94959255ef25546e966180d9a39f53334d81c.png)

and this one is working properly.

Thank you,

Eranda.
