Converting string to web-safe Base64 format

后端 未结 3 494
名媛妹妹
名媛妹妹 2020-12-03 12:58

I am testing how to update user picture using the Admin SDK Directory Service with Google Apps Scripts with the following function:

function updatePhoto(){
          


        
3条回答
  •  清歌不尽
    2020-12-03 13:48

    I know that this is quite old, but I'm working in something similar and I want to share my solution. You can use this function to convert your string to a base64safeurl string:

    protected static string Base64ForUrlEncode(string str)
            {
    
                StringBuilder result = new StringBuilder(Convert.ToBase64String(Encoding.ASCII.GetBytes(str)).TrimEnd('='));
                result.Replace('+', '-');
                result.Replace('/', '_');
                return result.ToString();
            }
    

    More info here: http://www.codeproject.com/Tips/76650/Base-base-url-base-url-and-z-base-encoding

    Note: This is C# code, so this solution is for .NET developments.

提交回复
热议问题