Issues with Base64 Decode - Base64.decodeAsBinary()

Curious if anyone has any thoughts or can see if I’m just doing something wrong…

I have a pipeline that’s fetching content files from Salesforce. These are received in BASE64 format and need to be decoded to binary before posting them to an internal application. If I leave the Salesforce results as-is (BASE64) and just try to send them to the REST POST snap with an inline Base64.decodeAsBinary() if fails with a weird error about bad Base64 input characters.

However, if instead I hookup an actual Document-to-Binary (BASE64 DECODE) and then re-encode with a Binary-to-Document (BASE64 ENCODE) and then pass that to the REST POST snap still with an inline Base64.decodeAsBinary() it seems to work fine…

Seems weird… Obviously I would prefer to just do the first method, rather than decoding/encoding/decoding like the second method.

Any ideas?

Also, if I take the raw BASE64 data from Salesforce and decode it with “base64 -d” it decodes just fine, like the bottom branch decodes it just fine (twice).

Can you give a little more information on the configuration of the “REST GET_FILE” snap? Is it a REST Get snap with the response type set to BINARY? Or, is the response type set to TEXT and $entity is a string?

Hi Tim,

The REST GET is setup with response type BINARY which puts the BASE64 encoded data into the entity field with a “_snaptype_binary_base64”, which I can’t decode directly with the Base64.decodeAsBinary($entity) function.

However, if I BASE64 decode it with the Document-To-Binary snap and then re-BASE64 encode it with the Binary-To-Document snap, I end up with the same BASE64 data in a content field, without any “_snaptype_binary_base64”, which then decodes fine with the Base64.decodeAsBinary($content) function.

image

Sorry, for the confusion, but I think the data is already binary (a byte array internally). The “_snaptype_binary_base64” is how the byte array is stored as JSON for preview. Have you tried just using $entity in the REST POST snap?

Hmm… I wonder how the DECODE BASE64 on the lower branch works then?

I’ll mess with it more.

It might not be doing anything at all since it’s already a byte array.

Hi @christwr , I believe that the base64 encode-decode inbuilt functions has some limitations and the encoding-decoding doesnt support all characters.
In the second approach i guess the data is not being transferred as it is supposed to be even though its working (please verify it).

my suggestion: use a script snap with python code for base64 encoding and decoding functionality.

Thanks.

What limitations have you found there to be? The functions were failing in this case because they were being passed raw binary data and not base64-encoded strings.