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

Azure Storage: Create a Short-Lived Service SAS for One Blob

See more Azure Cloud Storage Examples

Create an HTTPS-only service SAS for writing exactly /examplecontainer/example.bin. The canonical resource is URL-decoded and includes /blob/account/container/blob. This is a Blob service SAS, not a universal layout for Files, Tables or Queues. It uses the modern signature layout including the encryption-scope field, even when empty. Prefer user delegation SAS when Entra-based delegation is available.

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 service sas reference.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loTextCompare
LOCAL loConfig
LOCAL lnSameText1
LOCAL lnSameText2
LOCAL loSas
LOCAL loCanonical
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 = "sp,st,se,resource,si,sip,spr,sv,sr,snapshot,ses,rscc,rscd,rsce,rscl,rsct"
loCanonical = CreateObject('Chilkat.StringBuilder')
lnSuccess = loCanonical.Append("/blob/")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loSas
    RELEASE loCanonical
    CANCEL
ENDIF

lnSuccess = loCanonical.Append(loConfig.StringOf("account"))
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loSas
    RELEASE loCanonical
    CANCEL
ENDIF

lnSuccess = loCanonical.Append("/examplecontainer/example.bin")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loSas
    RELEASE loCanonical
    CANCEL
ENDIF

lnSuccess = loSas.SetNonTokenParam("resource",loCanonical.GetAsString())
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loSas
    RELEASE loCanonical
    CANCEL
ENDIF

lnSuccess = loSas.SetTokenParam("sr","sr","b")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loSas
    RELEASE loCanonical
    CANCEL
ENDIF

lnSuccess = loSas.SetTokenParam("sp","sp","w")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loSas
    RELEASE loCanonical
    CANCEL
ENDIF

lnSuccess = loSas.SetTokenParam("spr","spr","https")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loSas
    RELEASE loCanonical
    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
    RELEASE loCanonical
    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 loCanonical
    RELEASE loClock
    CANCEL
ENDIF

lnSuccess = loClock.AddSeconds(-300)
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loSas
    RELEASE loCanonical
    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 loCanonical
    RELEASE loClock
    CANCEL
ENDIF

lnSuccess = loClock.AddSeconds(1200)
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loSas
    RELEASE loCanonical
    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 loCanonical
    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 loCanonical
    RELEASE loClock
    CANCEL
ENDIF

loFiles = CreateObject('Chilkat.FileAccess')
lnSuccess = loFiles.WriteEntireTextFile("qa_data/azure/blob-sas.txt",lcToken,"utf-8",0)
IF (lnSuccess <> 1) THEN
    ? "Could not save token privately."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loSas
    RELEASE loCanonical
    RELEASE loClock
    RELEASE loFiles
    CANCEL
ENDIF

? "SAS saved privately; do not print the token."

RELEASE loTextCompare
RELEASE loConfig
RELEASE loSas
RELEASE loCanonical
RELEASE loClock
RELEASE loFiles