Azure Blob: Set and Search Index Tags
See more Azure Cloud Storage Examples
Optionally replace one blob's index tags, then search within a named container using Find Blobs by Tags and follow every continuation marker. Set setTags to true to perform the write. AddQueryParam handles query escaping; SQL-like tag-filter syntax still needs its own correct quoting when building expressions from input.
Tag indexing is asynchronous, so a just-written tag might not appear in immediate search results. Tag names and values are case-sensitive. Tags have their own permissions: writing tags and filtering blobs require different data actions (or SAS permissions t and f). Storage Blob Data Owner includes tag operations; check custom roles instead of assuming ordinary read/write rights suffice. The full tag set is replaced, with at most ten tags per blob.
Uses direct Chilkat.Rest requests and Azure public-cloud endpoints with verified HTTPS. REST requests select service version 2026-04-06. Create local input/output directories before running. Account-key examples read account and access_key string fields from private qa_data/azure/storage.json; do not embed secrets in distributed applications. Entra examples explain their own configuration. Keep credentials, bearer tokens, SAS URLs and diagnostic dumps private. Shared Key is supported only where allowed by account policy; Entra authentication is preferred where available.
Transport success and HTTP status are checked separately. Writes are not automatically replayed after an uncertain response. IDs, ETags, continuation markers and file sizes are strings; counters and explicitly bounded offsets use int. No webhook or web server is required.
Chilkat Lua Downloads
local chilkat = require("chilkat")
-- StringBuilder compares text by value in every generated language.
local textCompare = chilkat.StringBuilder.new()
-- Assumes Chilkat is unlocked. See Global Unlock Sample.
local success = false
local config = chilkat.JsonObject.new()
config.strict = true
success = config:load_file("qa_data/azure/storage.json")
if not success then
print("Could not load private Azure configuration.")
return
end
textCompare:clear()
textCompare:set_string(config:string_of("account"))
local sameText1 = textCompare:contents_equal("", true)
if (config:json_type_of("account") ~= 1) or (sameText1) then
print("Supply the storage account name.")
return
end
-- access_key is the base64 account key, not a connection string or SAS.
textCompare:clear()
textCompare:set_string(config:string_of("access_key"))
local sameText2 = textCompare:contents_equal("", true)
if (config:json_type_of("access_key") ~= 1) or (sameText2) then
print("Supply the base64 account access key.")
return
end
local endpoint = chilkat.StringBuilder.new()
success = endpoint:append(config:string_of("account"))
if not success then
print("Could not prepare the request.")
return
end
success = endpoint:append(".blob.core.windows.net")
if not success then
print("Could not prepare the request.")
return
end
-- resourcePath is already URL-encoded. Encode each path segment once when adapting it.
-- Keep slash separators; names and paths are case-sensitive.
local resourcePath = "/examplecontainer/example.bin"
local rest = chilkat.Rest.new()
rest.connect_timeout_ms = 20000
rest.idle_timeout_ms = 60000
local azAuth = chilkat.AuthAzureStorage.new()
azAuth.account = config:string_of("account")
azAuth.access_key = config:string_of("access_key")
azAuth.service = "Blob"
azAuth.scheme = "SharedKey"
azAuth.xms_version = "2026-04-06"
success = rest:set_auth_azure_storage(azAuth)
if not success then
print("Could not configure Shared Key signing.")
return
end
local connection = chilkat.Socket.new()
connection.require_ssl_cert_verify = true
connection.max_read_idle_ms = 60000
connection.max_send_idle_ms = 60000
success = connection:connect(endpoint:get_as_string(), 443, true, 20000)
if not success then
print("TLS connection failed; inspect diagnostics privately.")
return
end
-- Do not replay a write automatically after losing its response.
success = rest:use_connection(connection, false)
if not success then
print("Could not prepare the request.")
return
end
local responseText = ""
local result = chilkat.Xml.new()
result.strict = true
local setTags = false
if setTags then
-- Replaces the full tag set, not an individual tag.
local tags = chilkat.Xml.new()
tags.tag = "Tags"
tags:update_child_content("TagSet|Tag|Key", "category")
tags:update_child_content("TagSet|Tag|Value", "example")
success = rest:add_query_param("comp", "tags")
if not success then
print("Could not prepare the request.")
return
end
success = rest:add_header("Content-Type", "application/xml; charset=utf-8")
if not success then
print("Could not prepare the request.")
return
end
responseText = rest:full_request_string("PUT", resourcePath, tags:get_xml())
if not rest.last_method_success then
print("Request did not complete; outcome may be uncertain.")
return
end
if rest.response_status_code ~= 204 then
print("HTTP status: " .. rest.response_status_code)
print("Azure error code: " .. rest:response_hdr_by_name("x-ms-error-code"))
print("Request ID: " .. rest:response_hdr_by_name("x-ms-request-id"))
-- Inspect any error body privately; do not log credentials, SAS URLs or payloads.
return
end
success = rest:clear_all_query_params()
if not success then
print("Could not prepare the request.")
return
end
success = rest:clear_all_headers()
if not success then
print("Could not prepare the request.")
return
end
rest:disconnect(10)
success = connection:connect(endpoint:get_as_string(), 443, true, 20000)
if not success then
print("TLS reconnection failed.")
return
end
success = rest:use_connection(connection, false)
if not success then
print("Could not prepare the request.")
return
end
end
resourcePath = "/"
success = rest:add_query_param("comp", "blobs")
if not success then
print("Could not prepare the request.")
return
end
success = rest:add_query_param("where", "@container = 'examplecontainer' AND \"category\" = 'example'")
if not success then
print("Could not prepare the request.")
return
end
success = rest:add_query_param("maxresults", "1000")
if not success then
print("Could not prepare the request.")
return
end
local seenMarkers = chilkat.Hashtable.new()
local marker = ""
local more = true
local page = 0
while more do
if page >= 1000 then
print("Page limit reached; results are incomplete. Save the continuation marker.")
return
end
responseText = rest:full_request_no_body("GET", resourcePath)
if not rest.last_method_success then
print("Request did not complete; outcome may be uncertain.")
return
end
if rest.response_status_code ~= 200 then
print("HTTP status: " .. rest.response_status_code)
print("Azure error code: " .. rest:response_hdr_by_name("x-ms-error-code"))
print("Request ID: " .. rest:response_hdr_by_name("x-ms-request-id"))
-- Inspect any error body privately; do not log credentials, SAS URLs or payloads.
return
end
success = result:load_xml(responseText)
if not success then
print("Expected well-formed XML.")
return
end
if not result:tag_equals("EnumerationResults") then
print("Unexpected XML response root.")
return
end
local count = result:num_children_at("Blobs")
local i = 0
while i < count do
result.i = i
print("Container: " .. result:get_child_content("Blobs|Blob[i]|ContainerName"))
print("Blob: " .. result:get_child_content("Blobs|Blob[i]|Name"))
i = i + 1
end
marker = result:get_child_content("NextMarker")
page = page + 1
textCompare:clear()
textCompare:set_string(marker)
local sameText3 = textCompare:contents_equal("", true)
if sameText3 then
more = false
else
if seenMarkers:contains(marker) then
print("Repeated marker; results are incomplete.")
return
end
success = seenMarkers:add_int(marker, 1)
if not success then
print("Could not prepare the request.")
return
end
if page > 1 then
success = rest:remove_query_param("marker")
if not success then
print("Could not prepare the request.")
return
end
end
success = rest:add_query_param("marker", marker)
if not success then
print("Could not prepare the request.")
return
end
rest:disconnect(10)
success = connection:connect(endpoint:get_as_string(), 443, true, 20000)
if not success then
print("TLS reconnection failed.")
return
end
success = rest:use_connection(connection, false)
if not success then
print("Could not prepare the request.")
return
end
end
end
print("Tag search complete. Index updates may not yet be visible.")