Sample code for 30+ languages & platforms
AutoIt

Azure Blob - Get Tags (Check if Blob Exists)

See more Azure Cloud Storage Examples

Gets the user-defined tags for a specified blob. This can also be used as a way to check to see if a blob exists.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.

$oRest = ObjCreate("Chilkat.Rest")

; Connect to the Azure Storage Blob Service
Local $bTls = True
Local $iPort = 443
Local $bAutoReconnect = True
; In this example, the storage account name is "chilkat".
$bSuccess = $oRest.Connect("chilkat.blob.core.windows.net",$iPort,$bTls,$bAutoReconnect)
If ($bSuccess <> True) Then
    ConsoleWrite($oRest.LastErrorText & @CRLF)
    Exit
EndIf

; Provide Azure Cloud credentials for the REST call.
$oAzAuth = ObjCreate("Chilkat.AuthAzureStorage")
$oAzAuth.AccessKey = "AZURE_ACCESS_KEY"
; The account name used here should match the 1st part of the domain passed in the call to Connect (above).
$oAzAuth.Account = "chilkat"
$oAzAuth.Scheme = "SharedKey"
$oAzAuth.Service = "Blob"
; This causes the "x-ms-version: 2021-08-06" header to be automatically added.
$oAzAuth.XMsVersion = "2021-08-06"
$bSuccess = $oRest.SetAuthAzureStorage($oAzAuth)

; Note: The application does not need to explicitly set the following
; headers: Content-Length, x-ms-date, Authorization.  These headers
; are automatically set by Chilkat.

; The Azure blob container is "test", the file is "helloWorld.txt"
; Add "?comp=tags" to get the user-defined tags instead of the actual blob content.
$oSb = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oRest.FullRequestNoBodySb("GET","/test/helloWorldajdfadf.txt?comp=tags",$oSb)
If ($bSuccess = False) Then
    ; Examine the request/response to see what happened.
    ConsoleWrite("response status code = " & $oRest.ResponseStatusCode & @CRLF)
    ConsoleWrite("response status text = " & $oRest.ResponseStatusText & @CRLF)
    ConsoleWrite("response header: " & $oRest.ResponseHeader & @CRLF)
    ConsoleWrite("---" & @CRLF)
    ConsoleWrite("LastRequestStartLine: " & $oRest.LastRequestStartLine & @CRLF)
    ConsoleWrite("LastRequestHeader: " & $oRest.LastRequestHeader & @CRLF)
    Exit
EndIf

; A typical blob with no tags will return this:

; <?xml version="1.0" encoding="utf-8"?>
; <Tags><TagSet/></Tags>

; If the blob does not exist, you get this:

; <?xml version="1.0" encoding="utf-8"?>
; <Error>
;     <Code>BlobNotFound</Code>
;     <Message>The specified blob does not exist.
; 	RequestId:fcfefdd9-301e-001a-2135-3a23d2000000
; 	Time:2023-02-06T14:17:00.7805577Z
;     </Message>
; </Error>

ConsoleWrite($oSb.GetAsString() & @CRLF)

; To see if we got Tags or an Error, then examine the XML.
$oXml = ObjCreate("Chilkat.Xml")
$oXml.LoadSb($oSb,True)

; Examine the tag..
If ($oXml.TagEquals("Tags") = True) Then
    ConsoleWrite("Blob exists!" & @CRLF)
Else

    If ($oXml.ChildContentMatches("Code","BlobNotFound",True) = True) Then
        ConsoleWrite("Blob does not exist." & @CRLF)
    Else
        ConsoleWrite("Some other error..." & @CRLF)
    EndIf

EndIf

ConsoleWrite("Success." & @CRLF)