Sample code for 30+ languages & platforms
Tcl Requires Chilkat v11.6.0+

Azure Blob: Download a File Using a Complete SAS URL

See more Azure Cloud Storage Examples

Use a complete privately supplied HTTPS URL containing a valid SAS for the exact blob. This works with an appropriate service, account, or user delegation SAS; the consumer does not need the account key. The earlier embedded, expired token is removed. The required permission is read. Download to a staging file and rename only after success; choose a new final filename.

Keep the URL private and do not alter or double-encode the signature query. Redirects are disabled. This example uses Chilkat.Http directly for the full-URL convenience method; the other transfer examples show Chilkat.Rest.

Uses direct Chilkat REST calls with HTTPS certificate verification. Shared Key examples load a private qa_data/azure/storage.json file containing string fields account and access_key (the base64 account key). SAS consumers need only account there. Create local input/output directories before running. Examples target Azure public-cloud endpoints; adapt hostnames for other clouds or custom endpoints.

REST examples pin x-ms-version: 2026-04-06, and SAS generation uses the same service version. Complete-URL downloads use the supplied SAS version. This is a fully deployed version documented by Microsoft at review time. Older supported versions are not automatically obsolete. Transport completion and HTTP success are checked separately; writes are not automatically replayed after a lost response. Keep diagnostic dumps, keys and SAS URLs private.

Shared Key remains supported where allowed by account policy. Microsoft recommends Microsoft Entra ID, preferably managed identities where available, and user delegation SAS for delegated Blob access. Account-key SAS and Shared Key requests can be rejected when Shared Key access is disabled; these samples do not bypass that policy. See Azure data authorization.

Microsoft get blob reference.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

#  Use a privately supplied COMPLETE HTTPS blob URL with a current SAS query.
#  No account key is needed by this consumer.
set success 0
set savedUrl [new_CkStringBuilder]

set success [CkStringBuilder_LoadFile $savedUrl "qa_data/azure/blob-url.txt" "utf-8"]
if {$success != 1} then {
    puts "Could not load private SAS URL."
    delete_CkStringBuilder $savedUrl
    exit
}

set success [CkStringBuilder_Trim $savedUrl]
if {$success != 1} then {
    puts "Could not prepare the request."
    delete_CkStringBuilder $savedUrl
    exit
}

if {[CkStringBuilder_StartsWith $savedUrl "https://" 0] != 1} then {
    puts "An HTTPS SAS URL is required."
    delete_CkStringBuilder $savedUrl
    exit
}

set url [CkStringBuilder_getAsString $savedUrl]
set http [new_CkHttp]

CkHttp_put_RequireSslCertVerify $http 1
CkHttp_put_FollowRedirects $http 0
CkHttp_put_ConnectTimeout $http 20
CkHttp_put_ReadTimeout $http 60
set files [new_CkFileAccess]

if {[CkFileAccess_FileExists $files "qa_output/example.bin"] == 1} then {
    puts "Choose a new output filename."
    delete_CkStringBuilder $savedUrl
    delete_CkHttp $http
    delete_CkFileAccess $files
    exit
}

set success [CkHttp_Download $http $url "qa_output/example.bin.part"]
if {$success != 1} then {
    puts "Download failed; any staging file is incomplete."
    delete_CkStringBuilder $savedUrl
    delete_CkHttp $http
    delete_CkFileAccess $files
    exit
}

if {[CkHttp_get_LastStatus $http] != 200} then {
    puts "Unexpected download HTTP status."
    delete_CkStringBuilder $savedUrl
    delete_CkHttp $http
    delete_CkFileAccess $files
    exit
}

set success [CkFileAccess_FileRename $files "qa_output/example.bin.part" "qa_output/example.bin"]
if {$success != 1} then {
    puts "Could not publish the downloaded file."
    delete_CkStringBuilder $savedUrl
    delete_CkHttp $http
    delete_CkFileAccess $files
    exit
}

puts "SAS download completed."

delete_CkStringBuilder $savedUrl
delete_CkHttp $http
delete_CkFileAccess $files