Azure Cloud Storage API Guide
Azure Blob Storage holds text and binary objects in containers. Azure Files holds files and directories in file shares. This guide explains how to access both through their REST APIs with Chilkat and links to 53 complete examples covering authentication, uploads, downloads, resumable transfers, listing, recovery, and access control.
Choose a language for the example links below. Each link opens the complete example in that language. The guide text and request-mapping table stay the same. The native byte-array example is marked when unavailable.
Accounts, containers, blobs, and shares
A storage account supplies the service endpoint. A blob is addressed by its container and name; a file is addressed by its share, directory path, and filename. These operations generally use names in URLs, rather than first resolving opaque resource IDs. Blob names can contain slash-separated prefixes. In a flat-namespace account those prefixes do not create physical directories. Azure Files has directory resources. Hierarchical-namespace Blob accounts have additional directory semantics and need care when adapting recovery operations.
| Service | Example resource URL | Organization |
|---|---|---|
| Blob Storage | https://ACCOUNT.blob.core.windows.net/CONTAINER/NAME | Account, container, blob |
| Azure Files | https://ACCOUNT.file.core.windows.net/SHARE/DIRECTORY/FILE | Account, share, directory, file |
Encode individual path segments once, preserving the separating slashes. Use AddQueryParam for query values, including continuation markers and block IDs. The examples target Azure public-cloud endpoints; other clouds and custom endpoints require corresponding host and identity settings. Creating storage accounts through Azure Resource Manager is a separate management API. See Microsoft's Blob REST overview and FileREST overview.
Before running an example
Use Chilkat 11.6.0 or later and unlock the library. Replace sample resource names and local paths, and create the required local directories. The examples read configuration explicitly; they do not automatically discover Azure CLI credentials or refresh tokens. ETags, IDs, version timestamps, continuation markers, and stored sizes remain strings.
The examples select x-ms-version: 2026-04-06, which Microsoft documents as fully deployed as of October 29, 2026. Choosing a supported version makes request and response behavior explicit; an older supported version is not automatically obsolete. SAS signing layouts also depend on the SAS version. See Azure Storage versioning.
How an Azure request maps to Chilkat.Rest
Rest exposes the method, path, query, headers, and body directly. Most examples establish a certificate-verified TLS connection with Socket and pass it to Rest.UseConnection. The connection is configured without automatic reconnection so an uncertain write is not silently repeated. The two complete-SAS-URL transfer examples use Http.
| HTTP component | Chilkat usage |
|---|---|
| Account-key authorization | Configure AuthAzureStorage.Account, AccessKey, Service, and XMsVersion; attach it with SetAuthAzureStorage. Chilkat signs requests. |
| Bearer authorization | Add the Authorization: Bearer … header and x-ms-version. Use a token intended for Azure Storage. |
| Query and request headers | AddQueryParam and AddHeader. Clear request-specific values before reusing a Rest object for another operation. |
| Text, binary, or streamed request body | FullRequestString, FullRequestBd, or FullRequestStream. |
| Response and download body | Check transport completion and ResponseStatusCode. For streamed downloads, inspect headers before calling ReadRespBodyStream. |
See the Rest reference, AuthAzureStorage reference, and AuthAzureSAS reference.
Authorization
Microsoft recommends Entra ID and managed identities where available. Shared Key remains usable when account policy permits it; an account key is broad authority, not a per-file credential. SAS delegates a defined set of operations for a limited time. See Azure data authorization.
| Method | Application requirements |
|---|---|
| Entra client credentials | A confidential application that can protect its credentials. Assign a Blob data role; management-plane Contributor alone does not grant access to blob contents. |
| Managed identity | An eligible Azure host with an assigned identity and data permissions. The linked example uses the Azure VM IMDS endpoint; App Service, Functions, and Azure Arc have different endpoint details. |
| Shared Key | The storage account name and base64 account key. Account policy must allow this authentication method. |
| SAS | A current token or complete SAS URL whose scope, permissions, protocol, and expiry allow the requested operation. See the SAS section. |
Shared Key examples read qa_data/azure/storage.json with string fields account and access_key. Client-credentials authentication uses account, tenant_id, client_id, and client_secret in that file. The managed-identity example needs account and optionally managed_client_id. Keep configuration outside publicly served content and source control.
Both authentication examples request a Storage-audience token, use it to read blob properties, and save it privately as qa_data/azure/storage-token.json with an expires_at timestamp. Reacquire a token before expiry; these app-only flows do not use refresh tokens. The user delegation SAS and Azure Files OAuth examples consume this saved token. A successful token request does not prove the identity has permission to access a particular resource.
Uploading Blobs
Use a single Put Blob request for a straightforward upload. Choose a UTF-8 string for text, BinData for bytes already in memory, or a Stream for a local file. Streaming limits application memory use but does not make a single request resumable. If-None-Match: * in these examples prevents replacing an existing destination.
For the selected API version, one Put Blob can contain up to 5,000 MiB. Block uploads stage individual blocks and publish them with Put Block List; the service supports up to 4,000 MiB per block and 50,000 committed blocks. The examples use smaller 4 MiB blocks. Block IDs are Base64 values with equal decoded lengths, and the lowercase blockid query value must be escaped. See Put Blob, Put Block, and Put Block List.
The MD5 example sends the Base64 hash of each block, not a hexadecimal string. This checks that block's transfer; it does not automatically set the complete blob's content MD5. The resumable example saves a source SHA-256 fingerprint, size, destination, block size, and upload ID. On restart it reconciles uncommitted blocks and sends missing ones. Commit metadata lets it recognize its own completed upload after a lost response. Keep the source unchanged and use one process per checkpoint.
- Create a Block Blob with Metadata
- Stream a File to a Block Blob
- Upload UTF-8 Text to a Block Blob
- Upload BinData to a Block Blob
- Upload a Byte Array to a Block BlobNative byte-array upload is unavailable in this language. Use the BinData upload example above.
- Create an Empty Block Blob
- Upload Blocks and Commit
- Upload Blocks with Content-MD5 and Commit
- Resume a Block Upload from a Checkpoint
Downloading Blobs
Choose memory for small binary content, text decoding only for a known encoding, and streaming for larger files. A completed HTTP exchange can still contain an Azure error response. The file examples check the status, write to a staging file, and publish the final filename only after a successful transfer.
A byte-range request uses inclusive start and end positions and normally returns 206. Keep a range binary: its boundaries can split a UTF-8 character. The resumable example records the ETag and size, checks the version again on restart, and sends If-Match on every range. It verifies the returned ETag, Content-Range, Content-Length, and byte count before appending. See Get Blob.
The resumable download deliberately caps offsets at 2,000,000,000 bytes for portable int arithmetic. This is a sample limit, not an Azure limit. Its checkpoint identifies the remote version but does not authenticate the local partial file: keep that file private, unchanged, and exclusive to the download. If the blob changes, start separately rather than combining versions.
Listing, Tags and Deleting Blobs
Listings continue until NextMarker is empty, including after an empty page. Treat markers as opaque strings and pass them through AddQueryParam. The examples detect repeated markers and stop explicitly at a bounded page count rather than claim an incomplete listing is complete. A Name marked Encoded="true" needs URL decoding for display. See List Blobs.
Blob index tags are separate from metadata. Read tags when you need their values; use HEAD/Get Blob Properties to check existence and properties. Writing tags replaces the complete tag set, while Find Blobs by Tags searches the index. Tag permissions differ from ordinary content permissions, and indexing delay means a newly written tag may not appear immediately. See Find Blobs by Tags.
Deletion is disabled by default in the example. Review the target, leases, snapshots, retention, and immutability requirements before enabling it. A successful deletion request does not mean every version or retained copy has been permanently erased. See Delete Blob.
Blob Properties, Copying and Recovery
HEAD retrieves properties without the blob body. Keep the quoted ETag exactly as returned and use If-Match when a change must apply only to the version you inspected. A 412 means the condition was not met; reread and decide how to reconcile the change. Setting metadata replaces the full metadata collection. See Set Blob Metadata.
Copy Blob can move content to another blob without transferring it through the application. A 202 is acceptance, not completion: retain the copy ID and poll destination properties for that same operation. The example uses a new destination and a bounded wait. If it remains pending, continue tracking the original ID rather than starting another copy. See Copy Blob.
The recovery example first lists versions, snapshots, and soft-deleted entries in a flat-namespace account. Undelete recovers eligible retained content; with versioning enabled, making an older version current can require copying it to the base blob. Select IDs explicitly and protect an existing destination with its ETag. Retention expiry, permanent deletion, and immutability affect recovery; hierarchical-namespace accounts use a different deletion-ID workflow. See Undelete Blob.
Containers
Containers organize blobs within an account. Create them privately, enumerate them with pagination, and read their properties or metadata as needed. Setting container metadata replaces the entire metadata collection. Deleting a container affects everything it contains, so the deletion example requires an explicit change before it runs.
A stored access policy is a named permission/time policy that a service SAS can reference. It is different from Entra RBAC and anonymous public access. Setting the container ACL replaces its stored policy collection; preserve policies still in use and allow for propagation. See Set Container ACL.
A container lease protects container deletion. It does not lock the contents against blob uploads or edits. The example requests a 15-second lease and keeps the ID returned by Azure; use that ID for renewal or release, and for a permitted deletion while the lease is active. See Lease Container.
Blob Service Properties
These properties configure the account's Blob service, not an individual blob. Read current configuration before changing it. The write example enables seven-day blob soft delete and sends only that property group. It does not enable container soft delete or configure Azure Monitor. Retention can affect storage costs. See Set Blob Service Properties.
Replication statistics come from the ACCOUNT-secondary.blob.core.windows.net endpoint when read-access geo-redundant replication is enabled, such as RA-GRS or RA-GZRS. Continue signing with the primary account name. Last-sync information can be absent or unavailable; secondary reads may lag the primary. See Get Blob Service Stats.
CORS preflight checks whether the service's CORS rules allow a browser origin, method, and headers. It is an unsigned OPTIONS request and does not demonstrate authorization to perform the actual operation. Native Chilkat clients are not subject to browser CORS enforcement. See Preflight Blob Request.
Shared Access Signatures (SAS)
| Type | Signing authority and scope |
|---|---|
| Account SAS | Signed with an account key. Can cover selected services and resource types across the account; the sample's blob-write permission is not restricted to one blob. |
| Service SAS | Signed with an account key and scoped to a service resource. The generator here targets one blob. |
| User delegation SAS | Signed with a delegation key obtained using Entra authentication. The sample grants read access to one blob; effective access is also limited by the issuing principal's permissions. |
The generators use short validity windows and HTTPS-only access. Account-key SAS generators demonstrate writes; the user delegation example creates a read-only complete URL. Use a token with permissions matching the consumer: a write-only SAS cannot be used for a download. Consumers of an issued SAS do not need the account key.
AuthAzureSAS builds the token from explicit signing fields. Required empty positions in the string-to-sign still matter. The user delegation example includes the optional user-binding and signed-request field positions required by the 2026-04-06 layout, leaving unused values empty. It uses the returned delegation key and its validity interval, not the account key. The requesting identity needs permission to obtain that key as well as the relevant blob access. See account SAS, service SAS, and user delegation SAS.
The existing account/service generators save private token files. The user delegation generator saves qa_data/azure/read-blob-url.txt; the complete-URL download example reads qa_data/azure/blob-url.txt, so adapt that input path when using them together. Protect full SAS URLs as credentials. Account policy can reject account-key SAS, and user delegation SAS does not support stored access policies.
Azure File Service
FileREST addresses a share, directory, and file on the file.core.windows.net endpoint. Directory creation and rename examples target SMB shares; do not assume every SMB operation is available for NFS. Listing shares through FileREST remains supported, while Azure Resource Manager is the recommended interface for share management. Directory enumeration follows markers and distinguishes file entries from directory entries. See the FileREST reference.
The upload examples create or replace a file with its final length, then write ranges of at most 4 MiB. A failed range upload can leave a partially written remote file. Upload to a temporary remote name and rename only after completion when the application needs that publication pattern. The rename example refuses to replace an existing destination; account for open handles and leases. The multi-range sample uses a 2,000,000,000-byte bound for its int offsets. See Put Range and Rename File.
The Entra download uses a Storage token plus x-ms-file-request-intent: backup. FileREST OAuth requires the applicable backup-semantics data permissions; Storage File Data Privileged Reader is the built-in read role used here. This privileged access can bypass file and directory ACLs within the assigned scope. It is separate from SMB/Kerberos authentication, and ordinary SMB share-reader permissions are insufficient. The example applies to classic shares created through Microsoft.Storage. See Azure Files OAuth over REST.
- List Shares with Pagination
- Create an SMB Share Directory
- Create and Upload a Small File
- Upload a File in Multiple Ranges
- Download UTF-8 Text
- Download Binary Content to Memory
- Download to a File with Streaming
- List Directories and Files with Pagination
- Rename or Move a File
- Download with Entra OAuth and Backup Intent
Interpreting failures and retrying requests
Separate TLS/network failure, an Azure HTTP error, and an accepted operation that is still running. Record the HTTP status, x-ms-error-code, and x-ms-request-id when available, keeping verbose diagnostics private. A 403 can indicate authorization, SAS scope, account policy, or network restrictions; it is not an existence check. A 409 often requires resolving a resource-state conflict, and a 412 requires reconciling a failed condition.
Use bounded backoff for retryable failures and honor service retry guidance. After a lost write response, inspect remote state or saved operation/checkpoint information before repeating the write. Checkpoint files and bounded polling loops in these examples make uncertainty explicit; reaching a limit does not establish success. See Azure Storage status and error codes.