Sample code for 30+ languages & platforms
B4X

Base64 Encode a File

_LANGUAGE_ to Base64 encode the contents of a file.

Chilkat B4X Downloads

B4X
Dim success As Boolean = False

'  Get the contents of a file into a base64 encoded string:
Dim fac As ChilkatFileAccess
fac.Initialize
Dim strBase64 As String = fac.ReadBinaryToEncoded("c:/data/something.pdf", "base64")
If fac.LastMethodSuccess <> True Then
    Log(fac.LastErrorText)
    Return
End If


'  Now write the string to a file:
success = fac.WriteEntireTextFile("c:/data/something_pdf_base64.txt", strBase64, "us-ascii", False)
If success <> True Then
    Log(fac.LastErrorText)
    Return
End If


Log("Success!")