Convert Base64 with AL code

10 Jul

A couple of weeks ago, I was trying to write web service examples in AL code for VS Code. Unfortunately, at that time, it was not possible to call the Base64 methods on the TempBLOB table. And because those functions on the TempBLOB table are using .Net, I figured it was going to take a while before we get Base64 support in AL code. So I decided to write Base64 encoding / decoding routines myself. Just as an excercise and at that moment I didn’t know if I would even succeed.

Well, it turned out that it was possible and I ended up with a Codeunit that was able to convert a string to Base64 and also back into a string. At that moment, I already read in a GitHub issue that Microsoft promised to make the Base64 functions on TempBLOB table available in the next update. So I decided to not publish the code and wait for the next update.

However, a new question came up about Base64. And apparently, people were still interested in having the code. Because they were talking about a file I figured the code should not only support strings, but also binary data. That was another challenge that I just wanted to pick up. So I did. The Codeunit is now supporting both text and binary data. For binary data the code works with InStream and OutStream variables. In that way there is no dependency on any table.


I’m not going into the details of Base64 encoding itself. A great resource can be found here and here. I used these sites to understand how Base64 encoding really works and translated it to AL code.

You can download the code from GitHub.

3 thoughts on “Convert Base64 with AL code

  1. Pingback: Convert Base64 with AL code - Kauffmann @ Dynamics NAV - Dynamics NAV Users - DUG

  2. Hi Kauffmann
    Thank you for such an informative post. Can you please tell me if it is possible to change StreamToBase64String(instream) function’s parameter to Outstream? Will it make any difference to the logic?

    Thanks in advance 🙂

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.