Tcl
Tcl
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 Tcl Downloads
load ./chilkat.dll
set success 0
# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set http [new_CkHttp]
CkHttp_put_KeepResponseBody $http 1
set bd [new_CkBinData]
set success [CkHttp_DownloadBd $http "https://www.chilkatsoft.com/images/starfish.jpg" $bd]
set statusCode [CkHttp_get_LastStatus $http]
if {$success == 0} then {
if {$statusCode == 0} then {
# Unable to either send the request or get the response.
puts [CkHttp_lastErrorText $http]
} else {
# We got a response, but the status code was not in the 200s
puts "Response status code: $statusCode"
# Examine the response body.
puts "Response body:"
puts [CkHttp_lastResponseBody $http]
}
puts "Download failed."
} else {
puts "Download success, response status = $statusCode"
set base64_image_data [CkBinData_getEncoded $bd "base64"]
puts "image data in base64 format:"
puts "$base64_image_data"
}
delete_CkHttp $http
delete_CkBinData $bd