PowerBuilder
PowerBuilder
Download Image (JPG, GIF, etc.) to Base64
See more HTTP Examples
Demonstrates how to download an image, or any type of file, to get the data in base64 encoding format.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_Bd
integer li_StatusCode
string ls_Base64_image_data
li_Success = 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Http.KeepResponseBody = 1
loo_Bd = create oleobject
li_rc = loo_Bd.ConnectToNewObject("Chilkat.BinData")
li_Success = loo_Http.DownloadBd("https://www.chilkatsoft.com/images/starfish.jpg",loo_Bd)
li_StatusCode = loo_Http.LastStatus
if li_Success = 0 then
if li_StatusCode = 0 then
// Unable to either send the request or get the response.
Write-Debug loo_Http.LastErrorText
else
// We got a response, but the status code was not in the 200s
Write-Debug "Response status code: " + string(li_StatusCode)
// Examine the response body.
Write-Debug "Response body:"
Write-Debug loo_Http.LastResponseBody
end if
Write-Debug "Download failed."
else
Write-Debug "Download success, response status = " + string(li_StatusCode)
ls_Base64_image_data = loo_Bd.GetEncoded("base64")
Write-Debug "image data in base64 format:"
Write-Debug ls_Base64_image_data
end if
destroy loo_Http
destroy loo_Bd