PowerBuilder
PowerBuilder
Base64 Encode a File
_LANGUAGE_ to Base64 encode the contents of a file.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Fac
string ls_StrBase64
li_Success = 0
// Get the contents of a file into a base64 encoded string:
loo_Fac = create oleobject
li_rc = loo_Fac.ConnectToNewObject("Chilkat.FileAccess")
if li_rc < 0 then
destroy loo_Fac
MessageBox("Error","Connecting to COM object failed")
return
end if
ls_StrBase64 = loo_Fac.ReadBinaryToEncoded("c:/data/something.pdf","base64")
if loo_Fac.LastMethodSuccess <> 1 then
Write-Debug loo_Fac.LastErrorText
destroy loo_Fac
return
end if
// Now write the string to a file:
li_Success = loo_Fac.WriteEntireTextFile("c:/data/something_pdf_base64.txt",ls_StrBase64,"us-ascii",0)
if li_Success <> 1 then
Write-Debug loo_Fac.LastErrorText
destroy loo_Fac
return
end if
Write-Debug "Success!"
destroy loo_Fac