What is the correct format for the API SurveyQuestionImage.Data field?

前端 未结 1 587
小蘑菇
小蘑菇 2021-01-26 20:43

I am working with the GCS API, attempting to create a survey with image data.

I am using the NuGet package Google.Apis.ConsumerSurveys.v2 version 1.14.0.564 on the .Net

相关标签:
1条回答
  • 2021-01-26 21:16

    The data needs to be base64 encoded and also "urlsafe" or "websafe" depending on what language you are using. (python and java, respectively)

    In other words, you'll need to first base64 encode then:

    Web safe encoding uses '-' instead of '+', '_' instead of '/'

    Hope this helps!

    For c# users, check out this technique for making websafe b64:

    How to achieve Base64 URL safe encoding in C#?

    For .net users, look at the comments in this question:

    Converting string to web-safe Base64 format

    And also this link for more info about .net specific options for encoding:

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


    And to specifically answer the original poster, try this for converting your byte array to a string.

        public static string ToBase64ForUrlString(byte[] input)
        {
            StringBuilder result = new StringBuilder(Convert.ToBase64String(input).TrimEnd('='));
            result.Replace('+', '-');
            result.Replace('/', '_');
            return result.ToString();
        }
    
    0 讨论(0)
提交回复
热议问题