cancel
Showing results for 
Search instead for 
Did you mean: 

Issues with Base64 Decode - Base64.decodeAsBinary()

christwr
Contributor III

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?

image

8 REPLIES 8

christwr
Contributor III

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).

tstack
Former Employee

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?

christwr
Contributor III

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.

image

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?