DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoRest
Boolean iBTls
Integer iPort
Boolean iBAutoReconnect
Variant vAzAuth
Handle hoAzAuth
Variant vSb
Handle hoSb
Handle hoXml
String sTemp1
Integer iTemp1
Boolean bTemp1
Move False To iSuccess
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatRest)) To hoRest
If (Not(IsComObjectCreated(hoRest))) Begin
Send CreateComObject of hoRest
End
// Connect to the Azure Storage Blob Service
Move True To iBTls
Move 443 To iPort
Move True To iBAutoReconnect
// In this example, the storage account name is "chilkat".
Get ComConnect Of hoRest "chilkat.blob.core.windows.net" iPort iBTls iBAutoReconnect To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
// Provide Azure Cloud credentials for the REST call.
Get Create (RefClass(cComChilkatAuthAzureStorage)) To hoAzAuth
If (Not(IsComObjectCreated(hoAzAuth))) Begin
Send CreateComObject of hoAzAuth
End
Set ComAccessKey Of hoAzAuth To "AZURE_ACCESS_KEY"
// The account name used here should match the 1st part of the domain passed in the call to Connect (above).
Set ComAccount Of hoAzAuth To "chilkat"
Set ComScheme Of hoAzAuth To "SharedKey"
Set ComService Of hoAzAuth To "Blob"
// This causes the "x-ms-version: 2021-08-06" header to be automatically added.
Set ComXMsVersion Of hoAzAuth To "2021-08-06"
Get pvComObject of hoAzAuth to vAzAuth
Get ComSetAuthAzureStorage Of hoRest vAzAuth To iSuccess
// 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.
Get Create (RefClass(cComChilkatStringBuilder)) To hoSb
If (Not(IsComObjectCreated(hoSb))) Begin
Send CreateComObject of hoSb
End
Get pvComObject of hoSb to vSb
Get ComFullRequestNoBodySb Of hoRest "GET" "/test/helloWorldajdfadf.txt?comp=tags" vSb To iSuccess
If (iSuccess = False) Begin
// Examine the request/response to see what happened.
Get ComResponseStatusCode Of hoRest To iTemp1
Showln "response status code = " iTemp1
Get ComResponseStatusText Of hoRest To sTemp1
Showln "response status text = " sTemp1
Get ComResponseHeader Of hoRest To sTemp1
Showln "response header: " sTemp1
Showln "---"
Get ComLastRequestStartLine Of hoRest To sTemp1
Showln "LastRequestStartLine: " sTemp1
Get ComLastRequestHeader Of hoRest To sTemp1
Showln "LastRequestHeader: " sTemp1
Procedure_Return
End
// 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>
Get ComGetAsString Of hoSb To sTemp1
Showln sTemp1
// To see if we got Tags or an Error, then examine the XML.
Get Create (RefClass(cComChilkatXml)) To hoXml
If (Not(IsComObjectCreated(hoXml))) Begin
Send CreateComObject of hoXml
End
Get pvComObject of hoSb to vSb
Get ComLoadSb Of hoXml vSb True To iSuccess
// Examine the tag..
Get ComTagEquals Of hoXml "Tags" To bTemp1
If (bTemp1 = True) Begin
Showln "Blob exists!"
End
Else Begin
Get ComChildContentMatches Of hoXml "Code" "BlobNotFound" True To bTemp1
If (bTemp1 = True) Begin
Showln "Blob does not exist."
End
Else Begin
Showln "Some other error..."
End
End
Showln "Success."
End_Procedure