Azure Blob: Read Container Metadata
See more Azure Cloud Storage Examples
Read all x-ms-meta- response headers rather than assuming two particular keys exist. Header names are case-insensitive. Empty metadata is valid. Treat values as application data and avoid logging private metadata.
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 get container metadata reference.
Chilkat Unicode C Downloads
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkRestW.h>
#include <C_CkAuthAzureStorageW.h>
#include <C_CkSocketW.h>
#include <C_CkXmlW.h>
void ChilkatSample(void)
{
BOOL success;
HCkStringBuilderW textCompare;
HCkJsonObjectW config;
BOOL sameText1;
BOOL sameText2;
HCkStringBuilderW endpoint;
const wchar_t *resourcePath;
HCkRestW rest;
HCkAuthAzureStorageW azAuth;
HCkSocketW connection;
const wchar_t *responseText;
HCkXmlW result;
HCkStringBuilderW headerName;
int i;
success = FALSE;
// StringBuilder compares text by value in every generated language.
textCompare = CkStringBuilderW_Create();
// Assumes Chilkat is unlocked. See Global Unlock Sample.
success = FALSE;
config = CkJsonObjectW_Create();
CkJsonObjectW_putStrict(config,TRUE);
success = CkJsonObjectW_LoadFile(config,L"qa_data/azure/storage.json");
if (success != TRUE) {
wprintf(L"Could not load private Azure configuration.\n");
CkStringBuilderW_Dispose(textCompare);
CkJsonObjectW_Dispose(config);
return;
}
CkStringBuilderW_Clear(textCompare);
CkStringBuilderW_SetString(textCompare,CkJsonObjectW_stringOf(config,L"account"));
sameText1 = CkStringBuilderW_ContentsEqual(textCompare,L"",TRUE);
if ((CkJsonObjectW_JsonTypeOf(config,L"account") != 1) || (sameText1 == TRUE)) {
wprintf(L"Supply the storage account name.\n");
CkStringBuilderW_Dispose(textCompare);
CkJsonObjectW_Dispose(config);
return;
}
// access_key is the base64 account key, not a connection string or SAS.
CkStringBuilderW_Clear(textCompare);
CkStringBuilderW_SetString(textCompare,CkJsonObjectW_stringOf(config,L"access_key"));
sameText2 = CkStringBuilderW_ContentsEqual(textCompare,L"",TRUE);
if ((CkJsonObjectW_JsonTypeOf(config,L"access_key") != 1) || (sameText2 == TRUE)) {
wprintf(L"Supply the base64 account access key.\n");
CkStringBuilderW_Dispose(textCompare);
CkJsonObjectW_Dispose(config);
return;
}
endpoint = CkStringBuilderW_Create();
success = CkStringBuilderW_Append(endpoint,CkJsonObjectW_stringOf(config,L"account"));
if (success != TRUE) {
wprintf(L"Could not prepare the request.\n");
CkStringBuilderW_Dispose(textCompare);
CkJsonObjectW_Dispose(config);
CkStringBuilderW_Dispose(endpoint);
return;
}
success = CkStringBuilderW_Append(endpoint,L".blob.core.windows.net");
if (success != TRUE) {
wprintf(L"Could not prepare the request.\n");
CkStringBuilderW_Dispose(textCompare);
CkJsonObjectW_Dispose(config);
CkStringBuilderW_Dispose(endpoint);
return;
}
// resourcePath is already URL-encoded. Encode each path segment once when adapting it.
// Keep slash separators; names and paths are case-sensitive.
resourcePath = L"/examplecontainer";
rest = CkRestW_Create();
CkRestW_putConnectTimeoutMs(rest,20000);
CkRestW_putIdleTimeoutMs(rest,60000);
azAuth = CkAuthAzureStorageW_Create();
CkAuthAzureStorageW_putAccount(azAuth,CkJsonObjectW_stringOf(config,L"account"));
CkAuthAzureStorageW_putAccessKey(azAuth,CkJsonObjectW_stringOf(config,L"access_key"));
CkAuthAzureStorageW_putService(azAuth,L"Blob");
CkAuthAzureStorageW_putScheme(azAuth,L"SharedKey");
CkAuthAzureStorageW_putXMsVersion(azAuth,L"2026-04-06");
success = CkRestW_SetAuthAzureStorage(rest,azAuth);
if (success != TRUE) {
wprintf(L"Could not configure Shared Key signing.\n");
CkStringBuilderW_Dispose(textCompare);
CkJsonObjectW_Dispose(config);
CkStringBuilderW_Dispose(endpoint);
CkRestW_Dispose(rest);
CkAuthAzureStorageW_Dispose(azAuth);
return;
}
connection = CkSocketW_Create();
CkSocketW_putRequireSslCertVerify(connection,TRUE);
CkSocketW_putMaxReadIdleMs(connection,60000);
CkSocketW_putMaxSendIdleMs(connection,60000);
success = CkSocketW_Connect(connection,CkStringBuilderW_getAsString(endpoint),443,TRUE,20000);
if (success != TRUE) {
wprintf(L"TLS connection failed; inspect diagnostics privately.\n");
CkStringBuilderW_Dispose(textCompare);
CkJsonObjectW_Dispose(config);
CkStringBuilderW_Dispose(endpoint);
CkRestW_Dispose(rest);
CkAuthAzureStorageW_Dispose(azAuth);
CkSocketW_Dispose(connection);
return;
}
// Do not replay a write automatically after losing its response.
success = CkRestW_UseConnection(rest,connection,FALSE);
if (success != TRUE) {
wprintf(L"Could not prepare the request.\n");
CkStringBuilderW_Dispose(textCompare);
CkJsonObjectW_Dispose(config);
CkStringBuilderW_Dispose(endpoint);
CkRestW_Dispose(rest);
CkAuthAzureStorageW_Dispose(azAuth);
CkSocketW_Dispose(connection);
return;
}
result = CkXmlW_Create();
CkXmlW_putStrict(result,TRUE);
success = CkRestW_AddQueryParam(rest,L"restype",L"container");
if (success != TRUE) {
wprintf(L"Could not prepare the request.\n");
CkStringBuilderW_Dispose(textCompare);
CkJsonObjectW_Dispose(config);
CkStringBuilderW_Dispose(endpoint);
CkRestW_Dispose(rest);
CkAuthAzureStorageW_Dispose(azAuth);
CkSocketW_Dispose(connection);
CkXmlW_Dispose(result);
return;
}
success = CkRestW_AddQueryParam(rest,L"comp",L"metadata");
if (success != TRUE) {
wprintf(L"Could not prepare the request.\n");
CkStringBuilderW_Dispose(textCompare);
CkJsonObjectW_Dispose(config);
CkStringBuilderW_Dispose(endpoint);
CkRestW_Dispose(rest);
CkAuthAzureStorageW_Dispose(azAuth);
CkSocketW_Dispose(connection);
CkXmlW_Dispose(result);
return;
}
responseText = CkRestW_fullRequestNoBody(rest,L"HEAD",resourcePath);
if (CkRestW_getLastMethodSuccess(rest) != TRUE) {
wprintf(L"Request did not complete; outcome may be uncertain.\n");
CkStringBuilderW_Dispose(textCompare);
CkJsonObjectW_Dispose(config);
CkStringBuilderW_Dispose(endpoint);
CkRestW_Dispose(rest);
CkAuthAzureStorageW_Dispose(azAuth);
CkSocketW_Dispose(connection);
CkXmlW_Dispose(result);
return;
}
if (CkRestW_getResponseStatusCode(rest) != 200) {
wprintf(L"HTTP status: %d\n",CkRestW_getResponseStatusCode(rest));
wprintf(L"Azure error code: %s\n",CkRestW_responseHdrByName(rest,L"x-ms-error-code"));
wprintf(L"Request ID: %s\n",CkRestW_responseHdrByName(rest,L"x-ms-request-id"));
// Inspect any error body privately; do not log credentials, SAS URLs or payloads.
CkStringBuilderW_Dispose(textCompare);
CkJsonObjectW_Dispose(config);
CkStringBuilderW_Dispose(endpoint);
CkRestW_Dispose(rest);
CkAuthAzureStorageW_Dispose(azAuth);
CkSocketW_Dispose(connection);
CkXmlW_Dispose(result);
return;
}
wprintf(L"ETag: %s\n",CkRestW_responseHdrByName(rest,L"ETag"));
wprintf(L"Last-Modified: %s\n",CkRestW_responseHdrByName(rest,L"Last-Modified"));
headerName = CkStringBuilderW_Create();
i = 0;
while ((i < CkRestW_getNumResponseHeaders(rest))) {
CkStringBuilderW_SetString(headerName,CkRestW_responseHdrName(rest,i));
if (CkStringBuilderW_StartsWith(headerName,L"x-ms-meta-",FALSE) == TRUE) {
wprintf(L"%s: %s\n",CkStringBuilderW_getAsString(headerName),CkRestW_responseHdrValue(rest,i));
}
i = i + 1;
}
wprintf(L"Container operation completed.\n");
CkStringBuilderW_Dispose(textCompare);
CkJsonObjectW_Dispose(config);
CkStringBuilderW_Dispose(endpoint);
CkRestW_Dispose(rest);
CkAuthAzureStorageW_Dispose(azAuth);
CkSocketW_Dispose(connection);
CkXmlW_Dispose(result);
CkStringBuilderW_Dispose(headerName);
}