base64 encode/decode in custom code step

Hi folks,

Trying to base64 encode a string in a workflow custom code step but it looks like the Javascript functions btoa and aotb are not supported.

Does anyone know how I can achieve this?

Thanks in advance.

Hey @WaydeChristie1,

since the custom code actions came along, I dabble a bit with them in Python, but I’m not a dev. So, I don’t have any clue about JS and the methods you’re mentioning, buuuuuut… there is a module in the standard python library for this:

Would this be an option to try? Looks promising if you’re only doing that, but of course if the rest of your custom code action is also JS this is nonsense.

Cheers,

Chriso

Hey there @WaydeChristie1,
aotb and btoa have indeed been deprecated. The following would be how I’d go about the decoding/encoding process when working with base64:

let base64Str = "aGVsbG8=" 
let binary = Buffer.from(base64Str, "base64")
let decoded = binary.toString() 
console.log(binary)
console.log("Decoded base64 result:", decoded)

-------------

let str = "Encode Example"
let binary2 = Buffer.from(str)
let base64Encoded = binary2.toString("base64")
console.log("Encoded base 64 result:", base64Encoded)

Thanks very much nikodev. This is exactly what I needed :+1:

Here is a visualizer tool that breaks the process of Base64 encoding down step by step: