Problem converting Gmail api base64 email body

The 1C:Enterprise developers forum

#1
People who like this:0Yes/0No
Active user
Rating: 3
Joined: Feb 28, 2012
Company:

Hello,
I have made an integration with Gmail and need to convert the Base64 encoded body of the email into the original text.

I am using the following code:


       base64Msg = "<Long Base65 String>";
       binaryData = Base64Value(base64Msg);
emailContents = GetStringFromBinaryData(bdata);

The problem appears on the 2nd line. the return type of the function Base64Value() returns Undefined.
Is it because the string is too big?
How can i oveercome this problem?

The base64 string i put below. It is converted sucesfully if i copy-paste it in through the online tool: https://www.base64decode.org/

 
#2
People who like this:0Yes/0No
Administrator
Rating: 14
Joined: Oct 3, 2019
Company:

Hey Constantinos,

could you attach your base64 string as a separate file?

 
#3
People who like this:0Yes/0No
Active user
Rating: 3
Joined: Feb 28, 2012
Company:

Hi Aleksandr

please find the attached base64 file

https://drive.google.com/file/d/1Ey-MAJyNaLFYIwltoPdeH1lbSARpDpWn/view?usp=sharing

 
#4
People who like this:0Yes/0No
Administrator
Rating: 14
Joined: Oct 3, 2019
Company:

Hi Constantinos,

it's very simple :-)

Your file has a Base64url encoding, but not Base64. You can check it for example here: https://base64.guru/tools/repair

The difference between these encodings is described here: https://stackoverflow.com/questions/55389211/string-based-data-encoding-base64-vs-base64url

In short, the base64url uses the "-" symbol instead of the "+" symbol, and the "_" symbol instead of the "/" symbol.

Accordingly, to convert a Base64url to Base64, we just need to change these characters back.

The code below does this conversion.

Code
   base64Msg = stringSource;
   
   base64Msg = StrReplace(base64Msg,"-","+");
   base64Msg = StrReplace(base64Msg,"_","/");

   binaryData = Base64Value(base64Msg);
   
   emailContents = GetStringFromBinaryData(binaryData);   

 
Subscribe
Be the first to know tips & tricks on business application development!

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.