Azure blob storage search using tags c#

Drew Jackson 6 Reputation points
2022-04-13T20:28:24.763+00:00

I'm trying to search an Azure blob container for images using tags.

Here is my connection string:

<add key="blobConnString" value="DefaultEndpointsProtocol=https;AccountName=XXXX;AccountKey=XXXXXXXXXXXX;EndpointSuffix=core.windows.net"/>

Here is my method:

private void FindFiles()
{
    var foundItems = new List<TaggedBlobItem>();
    var connectionString = ConfigurationManager.AppSettings["blobConnString"];
    var _client = new BlobServiceClient(connectionString);
    var blobs = _client.FindBlobsByTags("@container = 'images' AND 'invID' = '12345'");
    foreach (var blob in blobs)
    {
        foundItems.Add(blob);
    }
}

And this is the error I get:

Error: Azure.RequestFailedException: Value for one of the query parameters specified in the request URI is invalid.
RequestId:7434f0b1-501e-0001-07a5-4ef3e1000000
Time:2022-04-12T19:45:01.1081429Z
Status: 400 (Value for one of the query parameters specified in the request URI is invalid.)
ErrorCode: InvalidQueryParameterValue

Additional Information:
QueryParameterName: comp
QueryParameterValue: blobs
Reason:

Content:
<?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidQueryParameterValue</Code><Message>Value for one of the query parameters specified in the request URI is invalid.
RequestId:7434f0b1-501e-0001-07a5-4ef3e1000000
Time:2022-04-12T19:45:01.1081429Z</Message><QueryParameterName>comp</QueryParameterName><QueryParameterValue>blobs</QueryParameterValue><Reason /></Error>

Headers:
Server: Microsoft-HTTPAPI/2.0
x-ms-request-id: 7434f0b1-501e-0001-07a5-4ef3e1000000
x-ms-client-request-id: c522b1bc-ce28-4c48-a593-dfbb6d81af66
x-ms-error-code: InvalidQueryParameterValue
Date: Tue, 12 Apr 2022 19:45:00 GMT
Content-Length: 376
Content-Type: application/xml

   at Azure.Storage.Blobs.ServiceRestClient.FilterBlobs(Nullable`1 timeout, String where, String marker, Nullable`1 maxresults, CancellationToken cancellationToken)
   at Azure.Storage.Blobs.BlobServiceClient.FindBlobsByTagsInternal(String marker, String expression, Nullable`1 pageSizeHint, Boolean async, CancellationToken cancellationToken)
   at Azure.Storage.Blobs.Models.FilterBlobsAsyncCollection.GetNextPageAsync(String continuationToken, Nullable`1 pageSizeHint, Boolean async, CancellationToken cancellationToken)
   at Azure.Core.Pipeline.TaskExtensions.EnsureCompleted[T](ValueTask`1 task)
   at Azure.Storage.StorageCollectionEnumerator`1.StoragePageable.GetEnumerator()+MoveNext()
   at CosmosGettingStartedTutorial.Program.FindFiles() in C:\Users\Drew\Downloads\DocumentDB-Quickstart-DotNet\sql-dotnet\CosmosGettingStartedTutorial\Program.cs:line 297
   at CosmosGettingStartedTutorial.Program.GetStartedDemoAsync() in C:\Users\Drew\Downloads\DocumentDB-Quickstart-DotNet\sql-dotnet\CosmosGettingStartedTutorial\Program.cs:line 78
   at CosmosGettingStartedTutorial.Program.Main(String[] args) in C:\Users\Drew\Downloads\DocumentDB-Quickstart-DotNet\sql-dotnet\CosmosGettingStartedTutorial\Program.cs:line 45
End of demo, press any key to exit.
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,425 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Drew Jackson 6 Reputation points
    2022-04-17T17:36:17.347+00:00

    For those that ever encounter this, the problem was the type of storage account I created on Azure. I had selected to use hierarchical namespacing and that was breaking the whole thing.

    1 person found this answer helpful.
    0 comments No comments

  2. shiva patpi 13,131 Reputation points Microsoft Employee
    2022-04-13T23:24:26.787+00:00

    Hello @Drew Jackson ,
    Below is the right syntax:

    static void AzureBlobSearch()
    {
    try
    {
    var foundItems = new List<TaggedBlobItem>();
    var connectionString = ConfigurationManager.ConnectionStrings["blob"].ConnectionString;
    var _client = new BlobServiceClient(connectionString);
    var queryString = @"container = 'test' AND ""test"" = 'test'";
    var blobs = _client.FindBlobsByTags(queryString);
    foreach (var blob in blobs)
    {
    foundItems.Add(blob);
    }
    }
    catch(Exception ex)
    {
    Console.WriteLine(ex.ToString());
    }
    }

    0 comments No comments

  3. Drew Jackson 6 Reputation points
    2022-04-14T12:50:33.33+00:00

    Changing the syntax didn't correct the error