Loading

How to Decode Base64 URL Encoded String

Дата публикации: Dec 18, 2024
Решение

SYMPTOM

You are getting the below error from the Transform Message component when you are using fromBase64 function:

Unable to transform String to Base 64 Binary. Reason : `Illegal base64 character 5f`

166| base64String as Binary {base: "64"} as Binary
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Trace:
at dw::core::Binaries::fromBase64 (line: 166, column: 5)
at main::main (line: 5, column: 21)

CAUSE

This error happens when the string that you are trying to transform contains a character not recognized by the basic Base 64 Alphabet.
For example:  “abcd3RkPUYY_Ybvckj==”, in this case, it is an underscore character.

SOLUTION

You can use the following dataweave script to decode it successfully:
%dw 2.0
import fromBase64 from dw::core::Binaries
output text/plain
---
fromBase64(payload.message replace /_/ with ("/") replace /-/ with("+") replace /\./ with(" "))

 


 
Номер статьи базы знаний

001119162

 
Загрузка
Salesforce Help | Article