Converting a binary file to Base64 in Lotus Script
Daniel Nashed – 28 February 2026 02:33:30
This took me a while. The devil is in the detail.
But finally I came up with something quite straightforward.
I had similar code in my blog which I finally took to build this helper function.
The Base64 encoding is needed for data source images which I will add in-line into Markdown.
-- Daniel
Function EncodeFileBase64 (FileName As String) As String
Dim session As New NotesSession
Dim stream As NotesStream
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim body As NotesMIMEEntity
Set stream = session.CreateStream
Call stream.Open(FileName, "Binary")
Set db = session.CurrentDatabase
Set doc = db.CreateDocument
Set body = doc.CreateMIMEEntity
Call body.SetContentFromBytes(stream, "application/octet-stream", ENC_IDENTITY_BINARY)
Call body.EncodeContent(ENC_BASE64)
EncodeFileBase64 = Replace(Replace(body.ContentAsText, Chr(13), ""), Chr(10), "")
Call stream.Close
Set doc = Nothing
End Function
- Comments [0]