metadata_storage_path error in .NET with Azure AI Search.

Hassan Kaleem 45 Reputation points
2024-05-14T10:27:27.2266667+00:00

Right now from my post api I am storing the address like UploadEmailAsync() in Azure Queue. I have tried saving it with and without JSON format but path which we use for Filters in Azure AI Search requires the base64 converted link. Right now i have tested the approaches where the link has been uploaded on Azure Queue and then the link has been rederived in the function app but when i convert that into base64 it is not filtering the data because the base64 string of url is missing the 0 at the end.
Here are the examples Link
https://xxxxxxx.blob.core.windows.net/xxxxxxxxx/submission/xxxxx-3504-4ea1-a6d2-b78f963d8d0b/rawemail.eml,
Now if i convert this into base 64 inside function app it is converted into this
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxvbi81YTJiOGFmZi0zNTA0LTRlYTEtYTZkMi1iNzhmOTYzZDhkMGIvcmF3ZW1haWwuZW1s
which Azure AI Search is not accepting it is accepting the base64 like this with 0 added
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxvbi81YTJiOGFmZi0zNTA0LTRlYTEtYTZkMi1iNzhmOTYzZDhkMGIvcmF3ZW1haWwuZW1s0
public async Task UploadEmailAsync(string base64Content, string name, string containerName)

{

// Decode the base64 string

byte[] data = Convert.FromBase64String(base64Content);

// Get a reference to a blob

BlobContainerClient containerClient = _blobServiceClient.GetBlobContainerClient(containerName);

BlobClient blobClient = containerClient.GetBlobClient(name);

//await SendMessageAsync(blobClient.Uri.ToString());

await SendMessageAsync(JsonConvert.SerializeObject(blobClient.Uri));

// Upload the blob

using (var stream = new MemoryStream(data, writable: false))

{

    await blobClient.UploadAsync(stream, overwrite: true);

}

}

public async Task SendMessageAsync(string message)

{

await _queueClient.SendMessageAsync(message);

}

Function App Code
public async Task<Uri> ReadMessagesFromQueueAsync()

{

try

{

    var response = await _queueClient.ReceiveMessagesAsync();

    if (response.Value.Any())

    {

        var message = response.Value.FirstOrDefault();

        var jsonUri = message.MessageText;

        // Deserialize the JSON string back into a URI object

        Uri uri = JsonConvert.DeserializeObject<Uri>(jsonUri);

        await _queueClient.DeleteMessageAsync(message.MessageId, message.PopReceipt);

        return uri;

    }

    else

    {

        return null;

    }

}

catch (Exception ex)

{

    Console.WriteLine($"Error receiving messages from the queue: {ex.Message}");

    throw;

}

}

public async Task<IActionResult> Classifier(Uri requestAddress)

{

Console.WriteLine(requestAddress);

try

{

    // Convert URL to base64 using URL-safe encoding

    string base64String = Convert.ToBase64String(Encoding.UTF8.GetBytes(requestAddress.ToString()));

    //base64String += "0";

    Console.WriteLine("Base64 string of blob URL: " + base64String);

    var searchText = "xxxxxxxxxxxxxxxxxxx";

    var head = "xxxxxxxxxxxxxxxxxxxxxx";

    _indexClient = new SearchIndexClient(new Uri(_searchServiceUri), new AzureKeyCredential(_queryApiKey));

    _searchClient = _indexClient.GetSearchClient(_searchServiceIndex);

    var options = new SearchOptions()

    {

        QueryType = Azure.Search.Documents.Models.SearchQueryType.Simple,

        IncludeTotalCount = true,

        Filter = $"metadata_storage_path eq '{base64String}'"

    };

    options.SearchFields.Add("metadata_message_to");

    options.SearchFields.Add("metadata_message_cc");

    var resultList = await _searchClient.SearchAsync<AzureAISearch>(head + " OR " + searchText, options);
Azure AI Search
Azure AI Search
An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
1,067 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,616 questions
Azure Queue Storage
Azure Queue Storage
An Azure service that provides messaging queues in the cloud.
109 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.