@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:
- Configure your REST connector to use the
pyAttachValues property, which is specifically designed for handling binary file content in Pega.
- 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.
- 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:
- In your REST connector configuration, navigate to the Headers section.
- Add your required headers:
- Set the Content-Type header to
application/octet-stream to indicate binary data
- Set the Authorization header to
Bearer <AccessToken>
- 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:
- 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
- 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
- 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: