cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Base64 to byte array conversion in CPI

0 Likes
2,315

Hello Experts,

We have a requirement to convert base64 value of a field and convert it into byte array format and pass it to target system. Could this be achieved through CPI interface ?

Regards,

Varun Vichare.

Accepted Solutions (1)

Accepted Solutions (1)

Sriprasadsbhat
Active Contributor
0 Likes

Hello Varun,

Yes this is possible and below is the snippet of groovy that does the same.

def s = 'Argh, Groovy you say, mate?'
 
String encoded = s.bytes.encodeBase64().toString()
assert 'QXJnaCwgR3Jvb3Z5IHlvdSBzYXksIG1hdGU/' == encoded
 
byte[] decoded = encoded.decodeBase64()
assert s == new String(decoded)

Regards,

Sriprasad Shivaram Bhat

Answers (1)

Answers (1)

MortenWittrock
SAP Mentor
SAP Mentor
0 Likes

Hi

Please keep in mind that if you are moving data over any protocol that expects text, then Base64 is the way to move binary data. Sending binary where text is expected is a recipe for problems.

Regards,

Morten