示例#1
0
    // This will get our upload url and on the response we will start our coroutine to take the screenshot
    public IEnumerator SubmitGoogleForm_UploadImage()
    {
        if (dontSend)
        {
            yield return(null);
        }
        else
        {
            takeScreenshot.TakeScreenShot(resWidth, redHeight, false);

            // wait until the image is ready (so takeScreenshot.imageByteArray won't be empty)
            while (takeScreenshot.imageReady == false)
            {
                print("waiting for image...");
                yield return(null);
            }
            Debug.Log("Image is ready: " + takeScreenshot.imageByteArray.Length + " bytes");
            string imageDataString = Convert.ToBase64String(takeScreenshot.imageByteArray);

            // create a Web Form, this will be the POST method's data
            var form = new WWWForm();
            form.AddField(_gform_image_timestamp, System.DateTime.Now.ToString(timeFormatStr));
            form.AddField(_gform_image_userid, USERID);
            //form.AddBinaryData("entry.936693460", takeScreenshot.imageByteArray, "screenshot.png", "image/png");  // or jpg
            form.AddField(_gform_image_image, imageDataString);

            string urlGoogleFormResponse = GoogleFormBaseUrl_image + "formResponse";
            // POST the screenshot to Google Forms
            using (UnityWebRequest www = UnityWebRequest.Post(urlGoogleFormResponse, form))
            {
                yield return(www.SendWebRequest());

                if (www.error != null)
                {
                    Debug.LogError(www.error);
                }
                else
                {
                    Debug.Log("Upload image: success");
                }
            }
        }
    }