Azure Storage: Create a Short-Lived Account SAS for Blob Writes
See more Azure Cloud Storage Examples
Create an HTTPS-only account SAS for Blob object writes (ss=b, srt=o, sp=w). It does not grant listing or deletion, but it still covers matching objects across the account; it is not constrained to one container or blob. Prefer a narrowly scoped service/user delegation SAS when that is the intended scope. Account SAS cannot refer to a stored access policy.
The token starts five minutes in the past for clock skew and expires fifteen minutes from now; account policy may require a shorter interval. Save it to a private token file and never log it. Generating a token locally does not validate the key, permissions, resource existence or account policy. Protect the signing account key and prefer short-lived delegation.
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 create account sas reference.
Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loTextCompare
LOCAL loConfig
LOCAL lnSameText1
LOCAL lnSameText2
LOCAL loSas
LOCAL loClock
LOCAL lcToken
LOCAL loFiles
lnSuccess = 0
* StringBuilder compares text by value in every generated language.
loTextCompare = CreateObject('Chilkat.StringBuilder')
* Assumes Chilkat is unlocked. See Global Unlock Sample.
lnSuccess = 0
loConfig = CreateObject('Chilkat.JsonObject')
loConfig.Strict = 1
lnSuccess = loConfig.LoadFile("qa_data/azure/storage.json")
IF (lnSuccess <> 1) THEN
? "Could not load private Azure configuration."
RELEASE loTextCompare
RELEASE loConfig
CANCEL
ENDIF
loTextCompare.Clear()
loTextCompare.SetString(loConfig.StringOf("account"))
lnSameText1 = loTextCompare.ContentsEqual("",1)
IF ((loConfig.JsonTypeOf("account") <> 1) OR (lnSameText1 = 1)) THEN
? "Supply the storage account name."
RELEASE loTextCompare
RELEASE loConfig
CANCEL
ENDIF
* access_key is the base64 account key, not a connection string or SAS.
loTextCompare.Clear()
loTextCompare.SetString(loConfig.StringOf("access_key"))
lnSameText2 = loTextCompare.ContentsEqual("",1)
IF ((loConfig.JsonTypeOf("access_key") <> 1) OR (lnSameText2 = 1)) THEN
? "Supply the base64 account access key."
RELEASE loTextCompare
RELEASE loConfig
CANCEL
ENDIF
loSas = CreateObject('Chilkat.AuthAzureSAS')
loSas.AccessKey = loConfig.StringOf("access_key")
* Commas represent LF separators; omitted optional fields still occupy their positions.
* This layout includes signedEncryptionScope (ses), required since version 2020-12-06.
loSas.StringToSign = "account,sp,ss,srt,st,se,sip,spr,sv,ses,"
lnSuccess = loSas.SetNonTokenParam("account",loConfig.StringOf("account"))
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loSas
CANCEL
ENDIF
lnSuccess = loSas.SetTokenParam("ss","ss","b")
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loSas
CANCEL
ENDIF
lnSuccess = loSas.SetTokenParam("srt","srt","o")
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loSas
CANCEL
ENDIF
lnSuccess = loSas.SetTokenParam("sp","sp","w")
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loSas
CANCEL
ENDIF
lnSuccess = loSas.SetTokenParam("spr","spr","https")
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loSas
CANCEL
ENDIF
lnSuccess = loSas.SetTokenParam("sv","sv","2026-04-06")
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loSas
CANCEL
ENDIF
loClock = CreateObject('Chilkat.CkDateTime')
lnSuccess = loClock.SetFromCurrentSystemTime()
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loSas
RELEASE loClock
CANCEL
ENDIF
lnSuccess = loClock.AddSeconds(-300)
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loSas
RELEASE loClock
CANCEL
ENDIF
lnSuccess = loSas.SetTokenParam("st","st",loClock.GetAsTimestamp(0))
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loSas
RELEASE loClock
CANCEL
ENDIF
lnSuccess = loClock.AddSeconds(1200)
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loSas
RELEASE loClock
CANCEL
ENDIF
lnSuccess = loSas.SetTokenParam("se","se",loClock.GetAsTimestamp(0))
IF (lnSuccess <> 1) THEN
? "Could not prepare the request."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loSas
RELEASE loClock
CANCEL
ENDIF
* Start is five minutes ago; expiry is fifteen minutes from now.
* Respect any stricter account SAS-expiration policy.
lcToken = loSas.GenerateToken()
IF (loSas.LastMethodSuccess <> 1) THEN
? "Could not generate SAS."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loSas
RELEASE loClock
CANCEL
ENDIF
loFiles = CreateObject('Chilkat.FileAccess')
lnSuccess = loFiles.WriteEntireTextFile("qa_data/azure/account-sas.txt",lcToken,"utf-8",0)
IF (lnSuccess <> 1) THEN
? "Could not save token privately."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loSas
RELEASE loClock
RELEASE loFiles
CANCEL
ENDIF
? "SAS saved privately; do not print the token."
RELEASE loTextCompare
RELEASE loConfig
RELEASE loSas
RELEASE loClock
RELEASE loFiles