(PowerBuilder) Base64 Encode a File
PowerBuilder to Base64 encode the contents of a file.
integer li_rc
oleobject loo_Fac
string ls_StrBase64
integer li_Success
// Get the contents of a file into a base64 encoded string:
loo_Fac = create oleobject
// Use "Chilkat_9_5_0.FileAccess" for versions of Chilkat < 10.0.0
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
|