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

Azure Blob: Upload Using a Service SAS

See more Azure Cloud Storage Examples

Read the private query token produced by the corresponding SAS-generation example and upload a small binary file to its matching account/path. Do not add a Shared Key Authorization header. If-None-Match: * prevents accidental overwrite; remove it only for intentional replacement. The same 5,000 MiB single-request service limit applies, but this example buffers input and is intended for small files.

Keep query values encoded exactly once. A 403 can mean expiry, start-time skew, wrong path, insufficient permissions, network restrictions or Shared Key being disabled. SAS is a bearer credential; do not print the URL or token.

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 put blob reference.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loTextCompare
LOCAL loConfig
LOCAL lnSameText1
LOCAL loEndpoint
LOCAL lcResourcePath
LOCAL loRest
LOCAL loConnection
LOCAL loResponseBody
LOCAL loResult
LOCAL loToken
LOCAL loData

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

loEndpoint = CreateObject('Chilkat.StringBuilder')
lnSuccess = loEndpoint.Append(loConfig.StringOf("account"))
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    CANCEL
ENDIF

lnSuccess = loEndpoint.Append(".blob.core.windows.net")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    CANCEL
ENDIF

*  resourcePath is already URL-encoded. Encode each path segment once when adapting it.
*  Keep slash separators; names and paths are case-sensitive.
lcResourcePath = "/examplecontainer/example.bin"
loRest = CreateObject('Chilkat.Rest')
loRest.ConnectTimeoutMs = 20000
loRest.IdleTimeoutMs = 60000
loConnection = CreateObject('Chilkat.Socket')
loConnection.RequireSslCertVerify = 1
loConnection.MaxReadIdleMs = 60000
loConnection.MaxSendIdleMs = 60000
lnSuccess = loConnection.Connect(loEndpoint.GetAsString(),443,1,20000)
IF (lnSuccess <> 1) THEN
    ? "TLS connection failed; inspect diagnostics privately."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    CANCEL
ENDIF

*  Do not replay a write automatically after losing its response.
lnSuccess = loRest.UseConnection(loConnection,0)
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    CANCEL
ENDIF

loResponseBody = CreateObject('Chilkat.StringBuilder')
loResult = CreateObject('Chilkat.Xml')
loResult.Strict = 1
lnSuccess = loRest.AddHeader("x-ms-version","2026-04-06")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResponseBody
    RELEASE loResult
    CANCEL
ENDIF

loToken = CreateObject('Chilkat.StringBuilder')
lnSuccess = loToken.LoadFile("qa_data/azure/blob-sas.txt","utf-8")
IF (lnSuccess <> 1) THEN
    ? "Could not load private SAS."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResponseBody
    RELEASE loResult
    RELEASE loToken
    CANCEL
ENDIF

lnSuccess = loToken.Trim()
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResponseBody
    RELEASE loResult
    RELEASE loToken
    CANCEL
ENDIF

IF (loToken.Length = 0) THEN
    ? "SAS file is empty."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResponseBody
    RELEASE loResult
    RELEASE loToken
    CANCEL
ENDIF

*  Load the raw query token; do not pre-encode it or add Shared Key authorization.
lnSuccess = loRest.AddQueryParams(loToken.GetAsString())
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResponseBody
    RELEASE loResult
    RELEASE loToken
    CANCEL
ENDIF

lnSuccess = loRest.AddHeader("x-ms-blob-type","BlockBlob")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResponseBody
    RELEASE loResult
    RELEASE loToken
    CANCEL
ENDIF

lnSuccess = loRest.AddHeader("If-None-Match","*")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResponseBody
    RELEASE loResult
    RELEASE loToken
    CANCEL
ENDIF

lnSuccess = loRest.AddHeader("Content-Type","application/octet-stream")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResponseBody
    RELEASE loResult
    RELEASE loToken
    CANCEL
ENDIF

loData = CreateObject('Chilkat.BinData')
lnSuccess = loData.LoadFile("qa_data/bin/sample.bin")
IF (lnSuccess <> 1) THEN
    ? "Could not read upload input."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResponseBody
    RELEASE loResult
    RELEASE loToken
    RELEASE loData
    CANCEL
ENDIF

loResponseBody.Clear()
lnSuccess = loRest.FullRequestBd("PUT",lcResourcePath,loData,loResponseBody)
IF (lnSuccess <> 1) THEN
    ? "Request did not complete; outcome may be uncertain."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResponseBody
    RELEASE loResult
    RELEASE loToken
    RELEASE loData
    CANCEL
ENDIF

IF (loRest.ResponseStatusCode <> 201) THEN
    ? "HTTP status: " + STR(loRest.ResponseStatusCode)
    ? "Azure error code: " + loRest.ResponseHdrByName("x-ms-error-code")
    ? "Request ID: " + loRest.ResponseHdrByName("x-ms-request-id")
    *  Inspect any error body privately; do not log credentials, SAS URLs or payloads.
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResponseBody
    RELEASE loResult
    RELEASE loToken
    RELEASE loData
    CANCEL
ENDIF

? "Blob created using SAS."

RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loConnection
RELEASE loResponseBody
RELEASE loResult
RELEASE loToken
RELEASE loData