cancel
Showing results for 
Search instead for 
Did you mean: 

Convert Binary file(not readable) to Base 64 format in SAP CPI

nidhi_srivastava22
Active Contributor
0 Kudos
285

Hi Experts,

I have a requirement where I am fetching a file(can be of .pdf/.xls/.word/.txt any format) from Azure DevOps portal and want to send that attachment file in base 64 format to Service Now.

The file fetched from Azure is coming in CPI in binary format(other than .txt file) and it is not readable format. The target system is only excepting base 64 encoded file.

Please guide me how can I convert the binary file getting downloaded in readable format?

Thanks,

Nidhi Srivastava

Accepted Solutions (1)

Accepted Solutions (1)

sivaramaraju_danthuluri
Product and Topic Expert
Product and Topic Expert

Hi ,Maybe you can try this 

import com.sap.gateway.ip.core.customdev.util.Message
import java.util.Base64

def Message processData(Message message) {
// Get the binary file content from the message body
byte[] binaryContent = message.getBody(byte[].class)

// Convert the binary content to Base64
String base64Content = Base64.getEncoder().encodeToString(binaryContent)

// Set the Base64 encoded content as the message body
message.setBody(base64Content)

// Set the file name in the message headers
def headers = message.getHeaders()
headers.put("FileName", "your_file_name_here.pdf") // Replace with the actual file name

return message
}
nidhi_srivastava22
Active Contributor
0 Kudos

Hi Siva,

Thanks for your inputs, this also works but I have used another way as I need to send output in JSON format.

Best Regards,

Nidhi Srivastava

Answers (0)