PowerBuilder
PowerBuilder
Download a Binary REST Response into BinData
See more REST Examples
Demonstrates Rest.FullRequestNoBodyBd, which sends a request with no body and stores the binary response body in a BinData.
The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background. This method is appropriate when the response is binary, such as an image or file download, allowing the received bytes to be saved or processed directly.
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Rest
integer li_BTls
integer li_BAutoReconnect
oleobject loo_BdResponse
integer li_BSaved
li_Success = 0
loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")
if li_rc < 0 then
destroy loo_Rest
MessageBox("Error","Connecting to COM object failed")
return
end if
li_BTls = 1
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("example.com",443,li_BTls,li_BAutoReconnect)
if li_Success = 0 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
return
end if
// The file paths are relative to the application's current working directory. Absolute paths
// may also be used. Supply the paths appropriate to your own environment.
// FullRequestNoBodyBd sends a request with no body and stores the binary response body in a
// BinData. This is appropriate when the response is binary, such as an image or file download.
loo_BdResponse = create oleobject
li_rc = loo_BdResponse.ConnectToNewObject("Chilkat.BinData")
li_Success = loo_Rest.FullRequestNoBodyBd("GET","/api/images/1",loo_BdResponse)
if li_Success = 0 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
destroy loo_BdResponse
return
end if
li_BSaved = loo_BdResponse.WriteFile("qa_output/image.png")
if li_BSaved <> 1 then
Write-Debug "Failed to save the response body."
destroy loo_Rest
destroy loo_BdResponse
return
end if
Write-Debug "Downloaded " + string(loo_BdResponse.NumBytes) + " bytes."
destroy loo_Rest
destroy loo_BdResponse