Azure Search invalid base64 path in metadata using Blob Storage Indexer

919 views Asked by At

I used Blob Storage Indexer to index my files in Azure Search.

After performing a search, I was supposed to be able to determine the path of blob by decoding a base64 metadata string. From what I can tell, C# is unable to decode the returned base64.

Here are sample base64 paths sent from Azure Search:

1. aHR0cHM6Ly9qbG9jYWxnZW5lcmFsLmJsb2IuY29yZS53aW5kb3dzLm5ldC9kaWFyaW9zLzEvMTAtdGV4dG8uemlw0 -> When I try to decode it in C#, I get the following exception: "Invalid length for a Base-64 char array or string." Code used is bellow

2.
aHR0cHM6Ly9qbG9jYWxnZW5lcmFsLmJsb2IuY29yZS53aW5kb3dzLm5ldC9kaWFyaW9zLzEvMi10ZXh0by56aXA1 -> adds a 5 to the end, that is not in the original path

3. aHR0cHM6Ly9qbG9jYWxnZW5lcmFsLmJsb2IuY29yZS53aW5kb3dzLm5ldC9kaWFyaW9zLzEvMy10ZXh0by56aXA1 -> adds a 5 to the end, that is not in the original path

Here is the code I am using to decode it:

    public static string DecodeBase64(this string base64)
    {
        // I have also tried with ASCII
        return System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(base64));
    }

enter image description here

1

There are 1 answers

0
Eugene Shvets On BEST ANSWER

Please refer to the documenation. Specifically, you need to use UrlTokenDecode method or an equivalent.