How to Send Binary File Data in Connector Request Body ?

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.

@Eranda10274 :warning: 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:

// Retrieve or create the binary data
// (This could be from a file attachment, database blob, etc.)
Binary binaryData = ...;

 
// Create a page for the attachment data
Page attachmentPage = tools.createPage("Data-ServiceMessage", "");

 
// Convert binary to Base64
String base64Content = Base64.getEncoder().encodeToString(binaryData);

 
// Set the attachment values
attachmentPage.putString("pyAttachValues", base64Content);
attachmentPage.putString("pyAttachNames", "yourFileName.ext");
attachmentPage.putString("pyAttachContentTypes", "application/octet-stream");

 
// Set this as the request attachment page
tools.putPage("pyRequestAttachmentPage", attachmentPage);

 
// For explicit header setting if needed
tools.getRequest().addHeader("Content-Type", "application/octet-stream");
tools.getRequest().addHeader("Authorization", "Bearer " + accessToken);

References:

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:

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.

and this one is working properly.

Thank you,

Eranda.