Azure Blob: Set a Stored Access Policy
See more Azure Cloud Storage Examples
Replace the stored-policy set with one short-lived read policy named example-read. The example omits x-ms-blob-public-access, leaving anonymous access disabled. This is not Microsoft Entra RBAC or an ADLS path ACL. A container supports at most five stored access policies. A service SAS can reference the identifier with si; account SAS and user delegation SAS cannot use these policies.
Disabled by default: replacement can revoke existing SAS access. Include every existing policy you intend to retain. Policy changes can take up to 30 seconds to propagate. The expiry is computed at run time, and the start is omitted to avoid an unnecessary clock-skew restriction.
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 set container acl reference.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoTextCompare
Boolean iApplyChange
Handle hoConfig
Boolean iSameText1
Boolean iSameText2
Handle hoEndpoint
String sResourcePath
Handle hoRest
Variant vAzAuth
Handle hoAzAuth
Variant vConnection
Handle hoConnection
String sResponseText
Handle hoResult
Handle hoExpiry
Handle hoPolicies
String sTemp1
Integer iTemp1
Boolean bTemp1
Move False To iSuccess
// StringBuilder compares text by value in every generated language.
Get Create (RefClass(cComChilkatStringBuilder)) To hoTextCompare
If (Not(IsComObjectCreated(hoTextCompare))) Begin
Send CreateComObject of hoTextCompare
End
Move False To iSuccess
Move False To iApplyChange
If (iApplyChange <> True) Begin
Showln "ACL replacement disabled. Review the target and set applyChange to true deliberately."
Procedure_Return
End
// Assumes Chilkat is unlocked. See Global Unlock Sample.
Get Create (RefClass(cComChilkatJsonObject)) To hoConfig
If (Not(IsComObjectCreated(hoConfig))) Begin
Send CreateComObject of hoConfig
End
Set ComStrict Of hoConfig To True
Get ComLoadFile Of hoConfig "qa_data/azure/storage.json" To iSuccess
If (iSuccess <> True) Begin
Showln "Could not load private Azure configuration."
Procedure_Return
End
Send ComClear To hoTextCompare
Get ComStringOf Of hoConfig "account" To sTemp1
Get ComSetString Of hoTextCompare sTemp1 To iSuccess
Get ComContentsEqual Of hoTextCompare "" True To iSameText1
Get ComJsonTypeOf Of hoConfig "account" To iTemp1
If ((iTemp1 <> 1) Or (iSameText1 = True)) Begin
Showln "Supply the storage account name."
Procedure_Return
End
// access_key is the base64 account key, not a connection string or SAS.
Send ComClear To hoTextCompare
Get ComStringOf Of hoConfig "access_key" To sTemp1
Get ComSetString Of hoTextCompare sTemp1 To iSuccess
Get ComContentsEqual Of hoTextCompare "" True To iSameText2
Get ComJsonTypeOf Of hoConfig "access_key" To iTemp1
If ((iTemp1 <> 1) Or (iSameText2 = True)) Begin
Showln "Supply the base64 account access key."
Procedure_Return
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoEndpoint
If (Not(IsComObjectCreated(hoEndpoint))) Begin
Send CreateComObject of hoEndpoint
End
Get ComStringOf Of hoConfig "account" To sTemp1
Get ComAppend Of hoEndpoint sTemp1 To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComAppend Of hoEndpoint ".blob.core.windows.net" To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
// resourcePath is already URL-encoded. Encode each path segment once when adapting it.
// Keep slash separators; names and paths are case-sensitive.
Move "/examplecontainer" To sResourcePath
Get Create (RefClass(cComChilkatRest)) To hoRest
If (Not(IsComObjectCreated(hoRest))) Begin
Send CreateComObject of hoRest
End
Set ComConnectTimeoutMs Of hoRest To 20000
Set ComIdleTimeoutMs Of hoRest To 60000
Get Create (RefClass(cComChilkatAuthAzureStorage)) To hoAzAuth
If (Not(IsComObjectCreated(hoAzAuth))) Begin
Send CreateComObject of hoAzAuth
End
Get ComStringOf Of hoConfig "account" To sTemp1
Set ComAccount Of hoAzAuth To sTemp1
Get ComStringOf Of hoConfig "access_key" To sTemp1
Set ComAccessKey Of hoAzAuth To sTemp1
Set ComService Of hoAzAuth To "Blob"
Set ComScheme Of hoAzAuth To "SharedKey"
Set ComXMsVersion Of hoAzAuth To "2026-04-06"
Get pvComObject of hoAzAuth to vAzAuth
Get ComSetAuthAzureStorage Of hoRest vAzAuth To iSuccess
If (iSuccess <> True) Begin
Showln "Could not configure Shared Key signing."
Procedure_Return
End
Get Create (RefClass(cComChilkatSocket)) To hoConnection
If (Not(IsComObjectCreated(hoConnection))) Begin
Send CreateComObject of hoConnection
End
Set ComRequireSslCertVerify Of hoConnection To True
Set ComMaxReadIdleMs Of hoConnection To 60000
Set ComMaxSendIdleMs Of hoConnection To 60000
Get ComGetAsString Of hoEndpoint To sTemp1
Get ComConnect Of hoConnection sTemp1 443 True 20000 To iSuccess
If (iSuccess <> True) Begin
Showln "TLS connection failed; inspect diagnostics privately."
Procedure_Return
End
// Do not replay a write automatically after losing its response.
Get pvComObject of hoConnection to vConnection
Get ComUseConnection Of hoRest vConnection False To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get Create (RefClass(cComChilkatXml)) To hoResult
If (Not(IsComObjectCreated(hoResult))) Begin
Send CreateComObject of hoResult
End
Set ComStrict Of hoResult To True
Get ComAddQueryParam Of hoRest "restype" "container" To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComAddQueryParam Of hoRest "comp" "acl" To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
// This replaces all stored access policies and leaves anonymous access disabled.
Get Create (RefClass(cComCkDateTime)) To hoExpiry
If (Not(IsComObjectCreated(hoExpiry))) Begin
Send CreateComObject of hoExpiry
End
Get ComSetFromCurrentSystemTime Of hoExpiry To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComAddSeconds Of hoExpiry 3600 To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get Create (RefClass(cComChilkatXml)) To hoPolicies
If (Not(IsComObjectCreated(hoPolicies))) Begin
Send CreateComObject of hoPolicies
End
Set ComTag Of hoPolicies To "SignedIdentifiers"
Send ComUpdateChildContent To hoPolicies "SignedIdentifier|Id" "example-read"
Get ComGetAsTimestamp Of hoExpiry False To sTemp1
Send ComUpdateChildContent To hoPolicies "SignedIdentifier|AccessPolicy|Expiry" sTemp1
Send ComUpdateChildContent To hoPolicies "SignedIdentifier|AccessPolicy|Permission" "r"
Get ComAddHeader Of hoRest "Content-Type" "application/xml" To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComGetXml Of hoPolicies To sTemp1
Get ComFullRequestString Of hoRest "PUT" sResourcePath sTemp1 To sResponseText
Get ComLastMethodSuccess Of hoRest To bTemp1
If (bTemp1 <> True) Begin
Showln "Request did not complete; outcome may be uncertain."
Procedure_Return
End
Get ComResponseStatusCode Of hoRest To iTemp1
If (iTemp1 <> 200) Begin
Get ComResponseStatusCode Of hoRest To iTemp1
Showln "HTTP status: " iTemp1
Get ComResponseHdrByName Of hoRest "x-ms-error-code" To sTemp1
Showln "Azure error code: " sTemp1
Get ComResponseHdrByName Of hoRest "x-ms-request-id" To sTemp1
Showln "Request ID: " sTemp1
// Inspect any error body privately; do not log credentials, SAS URLs or payloads.
Procedure_Return
End
Showln "Stored access policy replaced; allow time for propagation."
End_Procedure