Desktop version

Main > Forum > 1C:Enterprise Platform > 1C:Enterprise – Business applications platform > Problem converting Gmail api base64 email body

Forum

Search UsersRules
Problem converting Gmail api base64 email body
#1
Active user
Points:: 0
Joined:: Feb 28, 2012

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/

Profile
#2
Administrator
Points:: 0
Joined:: Oct 3, 2019

Hey Constantinos,

could you attach your base64 string as a separate file?

Profile
#3
Active user
Points:: 0
Joined:: Feb 28, 2012

Hi Aleksandr

please find the attached base64 file

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

Profile
#4
Administrator
Points:: 0
Joined:: Oct 3, 2019

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

Profile
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)



© 1C LLC. All rights reserved
1C Company respects the privacy of our customers and visitors
to our Web-site.