[Solved] Encode String as Base64

JEdward
JEdward New Altair Community Member
edited November 5 in Community Q&A
Hello,

I'd like to take an attribute value and encode it as base64, does anyone have any suggestions on how to do this using the Execute Script or another operator?

I'm struggling. 

Thanks,
JH
Tagged:

Best Answer

  • JEdward
    JEdward New Altair Community Member
    Answer ✓
    Solved it!  For anyone wanting to do the same, you can use the following code in the Execute Script operator. 

    ExampleSet eSet = operator.getInput(ExampleSet.class);
    for (Example example : eSet) {
    def s = example["Attribute Value"]
    String encoded = s.bytes.encodeBase64().toString()
    example["Attribute Value"] = encoded
    }

    return eSet;

Answers

  • JEdward
    JEdward New Altair Community Member
    Answer ✓
    Solved it!  For anyone wanting to do the same, you can use the following code in the Execute Script operator. 

    ExampleSet eSet = operator.getInput(ExampleSet.class);
    for (Example example : eSet) {
    def s = example["Attribute Value"]
    String encoded = s.bytes.encodeBase64().toString()
    example["Attribute Value"] = encoded
    }

    return eSet;