question

DrewJackson-6008 avatar image
0 Votes"
DrewJackson-6008 asked SumanthMarigowda-MSFT commented

Azure blob storage search using tags c#

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

shivapatpi-MSFT avatar image
0 Votes"
shivapatpi-MSFT answered

Hello @DrewJackson-6008 ,
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());
}
}

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DrewJackson-6008 avatar image
0 Votes"
DrewJackson-6008 answered shivapatpi-MSFT commented

Changing the syntax didn't correct the error

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I just tried it locally and I don't see any errors!

193263-image.png


0 Votes 0 ·
image.png (175.6 KiB)
DrewJackson-6008 avatar image
1 Vote"
DrewJackson-6008 answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.