0

I have set a Azure search for blob storage and since the path of the file is a key property it is encoded to Base 64 format. While searching the Index, I need to decode the path and display it in the front end. But when I try to do that in few of the scenarios it throws error.

 int mod4 = base64EncodedData.Length % 4;
            if (mod4 > 0)
            {
                base64EncodedData += new string('=', 4 - mod4);
            }
            var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
            return System.Text.Encoding.ASCII.GetString(base64EncodedBytes);

Please let me know what is the correct way to do it.

Thanks.

1 Answers1

1

Refer to Base64Encode and Base64Decode mapping functions - the encoding details are documented there.

In particular, if you're using .NET, you should use HttpServerUtility.UrlTokenDecode method with UTF-8 encoding, not ASCII.

Eugene Shvets
  • 4,561
  • 13
  • 19