Sample code for 30+ languages & platforms
PowerBuilder 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 PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_TextCompare
oleobject loo_Config
long li_SameText1
oleobject loo_Endpoint
string ls_ResourcePath
oleobject loo_Rest
oleobject loo_Connection
oleobject loo_ResponseBody
oleobject loo_Result
oleobject loo_Token
oleobject loo_Data

li_Success = 0

//  StringBuilder compares text by value in every generated language.
loo_TextCompare = create oleobject
li_rc = loo_TextCompare.ConnectToNewObject("Chilkat.StringBuilder")
if li_rc < 0 then
    destroy loo_TextCompare
    MessageBox("Error","Connecting to COM object failed")
    return
end if
//  Assumes Chilkat is unlocked. See Global Unlock Sample.
li_Success = 0
loo_Config = create oleobject
li_rc = loo_Config.ConnectToNewObject("Chilkat.JsonObject")

loo_Config.Strict = 1
li_Success = loo_Config.LoadFile("qa_data/azure/storage.json")
if li_Success <> 1 then
    Write-Debug "Could not load private Azure configuration."
    destroy loo_TextCompare
    destroy loo_Config
    return
end if

loo_TextCompare.Clear()
loo_TextCompare.SetString(loo_Config.StringOf("account"))
li_SameText1 = loo_TextCompare.ContentsEqual("",1)
if (loo_Config.JsonTypeOf("account") <> 1) OR (li_SameText1 = 1) then
    Write-Debug "Supply the storage account name."
    destroy loo_TextCompare
    destroy loo_Config
    return
end if

loo_Endpoint = create oleobject
li_rc = loo_Endpoint.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Endpoint.Append(loo_Config.StringOf("account"))
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Endpoint
    return
end if

li_Success = loo_Endpoint.Append(".blob.core.windows.net")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Endpoint
    return
end if

//  resourcePath is already URL-encoded. Encode each path segment once when adapting it.
//  Keep slash separators; names and paths are case-sensitive.
ls_ResourcePath = "/examplecontainer/example.bin"
loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")

loo_Rest.ConnectTimeoutMs = 20000
loo_Rest.IdleTimeoutMs = 60000
loo_Connection = create oleobject
li_rc = loo_Connection.ConnectToNewObject("Chilkat.Socket")

loo_Connection.RequireSslCertVerify = 1
loo_Connection.MaxReadIdleMs = 60000
loo_Connection.MaxSendIdleMs = 60000
li_Success = loo_Connection.Connect(loo_Endpoint.GetAsString(),443,1,20000)
if li_Success <> 1 then
    Write-Debug "TLS connection failed; inspect diagnostics privately."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_Connection
    return
end if

//  Do not replay a write automatically after losing its response.
li_Success = loo_Rest.UseConnection(loo_Connection,0)
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_Connection
    return
end if

loo_ResponseBody = create oleobject
li_rc = loo_ResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

loo_Result = create oleobject
li_rc = loo_Result.ConnectToNewObject("Chilkat.Xml")

loo_Result.Strict = 1
li_Success = loo_Rest.AddHeader("x-ms-version","2026-04-06")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Result
    return
end if

loo_Token = create oleobject
li_rc = loo_Token.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Token.LoadFile("qa_data/azure/blob-sas.txt","utf-8")
if li_Success <> 1 then
    Write-Debug "Could not load private SAS."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Result
    destroy loo_Token
    return
end if

li_Success = loo_Token.Trim()
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Result
    destroy loo_Token
    return
end if

if loo_Token.Length = 0 then
    Write-Debug "SAS file is empty."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Result
    destroy loo_Token
    return
end if

//  Load the raw query token; do not pre-encode it or add Shared Key authorization.
li_Success = loo_Rest.AddQueryParams(loo_Token.GetAsString())
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Result
    destroy loo_Token
    return
end if

li_Success = loo_Rest.AddHeader("x-ms-blob-type","BlockBlob")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Result
    destroy loo_Token
    return
end if

li_Success = loo_Rest.AddHeader("If-None-Match","*")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Result
    destroy loo_Token
    return
end if

li_Success = loo_Rest.AddHeader("Content-Type","application/octet-stream")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Result
    destroy loo_Token
    return
end if

loo_Data = create oleobject
li_rc = loo_Data.ConnectToNewObject("Chilkat.BinData")

li_Success = loo_Data.LoadFile("qa_data/bin/sample.bin")
if li_Success <> 1 then
    Write-Debug "Could not read upload input."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Result
    destroy loo_Token
    destroy loo_Data
    return
end if

loo_ResponseBody.Clear()
li_Success = loo_Rest.FullRequestBd("PUT",ls_ResourcePath,loo_Data,loo_ResponseBody)
if li_Success <> 1 then
    Write-Debug "Request did not complete; outcome may be uncertain."
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Result
    destroy loo_Token
    destroy loo_Data
    return
end if

if loo_Rest.ResponseStatusCode <> 201 then
    Write-Debug "HTTP status: " + string(loo_Rest.ResponseStatusCode)
    Write-Debug "Azure error code: " + loo_Rest.ResponseHdrByName("x-ms-error-code")
    Write-Debug "Request ID: " + loo_Rest.ResponseHdrByName("x-ms-request-id")
    //  Inspect any error body privately; do not log credentials, SAS URLs or payloads.
    destroy loo_TextCompare
    destroy loo_Config
    destroy loo_Endpoint
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_ResponseBody
    destroy loo_Result
    destroy loo_Token
    destroy loo_Data
    return
end if

Write-Debug "Blob created using SAS."


destroy loo_TextCompare
destroy loo_Config
destroy loo_Endpoint
destroy loo_Rest
destroy loo_Connection
destroy loo_ResponseBody
destroy loo_Result
destroy loo_Token
destroy loo_Data