(Tcl) Demonstrate S3_DownloadBytes
Demonstrates how to download a file into memory from the Amazon S3 service.
load ./chilkat.dll
# This example assumes the Chilkat HTTP API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set http [new_CkHttp]
CkHttp_put_AwsAccessKey $http "AWS_ACCESS_KEY"
CkHttp_put_AwsSecretKey $http "AWS_SECRET_KEY"
set bucketName "chilkat.qa"
set objectName "images/sea_creatures/starfish.jpg"
set localFilePath "qa_output/starfish.jpg"
set jpgBytes [new_CkByteData]
set success [CkHttp_S3_DownloadBytes $http $bucketName $objectName $jpgBytes]
if {[CkHttp_get_LastMethodSuccess $http] != 1} then {
puts [CkHttp_lastErrorText $http]
delete_CkHttp $http
delete_CkByteData $jpgBytes
exit
}
puts "Download successful."
set fac [new_CkFileAccess]
set success [CkFileAccess_WriteEntireFile $fac $localFilePath $jpgBytes]
puts "File saved success = $success"
delete_CkHttp $http
delete_CkByteData $jpgBytes
delete_CkFileAccess $fac
|