Beispiel #1
0
        /// <summary>
        /// Uploads a GIF image to your channel using your Giphy username and your app's API key.
        /// The GIF file can be stored on the local storage or at a provided URL.
        /// </summary>
        /// <param name="username">Your Giphy username.</param>
        /// <param name="apiKey">The API key for your app.</param>
        /// <param name="content">Content to upload.</param>
        /// <param name="uploadProgressCallback">Upload progress callback: the parameter indicates upload progress from 0 to 1.</param>
        /// <param name="uploadCompletedCallback">Upload completed callback: the parameter is the URL of the uploaded image.</param>
        /// <param name="uploadFailedCallback">Upload failed callback: the parameter is the error message.</param>
        public static void Upload(string username, string apiKey, GiphyUploadParams content, Action <float> uploadProgressCallback, Action <string> uploadCompletedCallback, Action <string> uploadFailedCallback)
        {
#if !UNITY_WEBPLAYER
            if (string.IsNullOrEmpty(content.localImagePath) && string.IsNullOrEmpty(content.sourceImageUrl))
            {
                Debug.LogError("UploadToGiphy FAILED: no image was specified for uploading.");
                return;
            }
            else if (!string.IsNullOrEmpty(content.localImagePath) && !System.IO.File.Exists(content.localImagePath))
            {
                Debug.LogError("UploadToGiphy FAILED: (local) file not found.");
                return;
            }

            // Append the API key to the upload URL itself, as simply adding it to the form doesn't really work.
            string uploadPath = GIPHY_UPLOAD_PATH + (string.IsNullOrEmpty(apiKey) ? string.Empty : "?api_key=" + apiKey);

            // Prepare upload form.
            WWWForm form = new WWWForm();
            form.AddField("api_key", apiKey);
            form.AddField("username", username);

            if (!string.IsNullOrEmpty(content.localImagePath) && System.IO.File.Exists(content.localImagePath))
            {
                form.AddBinaryData("file", FileUtil.ReadAllBytes(content.localImagePath));
            }

            if (!string.IsNullOrEmpty(content.sourceImageUrl))
            {
                form.AddField("source_image_url", content.sourceImageUrl);
            }

            if (!string.IsNullOrEmpty(content.tags))
            {
                form.AddField("tags", content.tags);
            }

            if (!string.IsNullOrEmpty(content.sourcePostUrl))
            {
                form.AddField("source_post_url", content.sourcePostUrl);
            }

            if (content.isHidden)
            {
                form.AddField("is_hidden", "true");
            }

            // Start uploading.
            Instance.StartCoroutine(CRUpload(uploadPath, form, uploadProgressCallback, uploadCompletedCallback, uploadFailedCallback));
#endif
        }
Beispiel #2
0
        /// <summary>
        /// Uploads a GIF image to your Giphy channel. Requires a username and a production API key.
        /// The GIF file can be stored on the local storage or at a provided URL.
        /// </summary>
        /// <param name="username">Your Giphy username.</param>
        /// <param name="apiKey">Production API key.</param>
        /// <param name="content">Content to upload.</param>
        /// <param name="uploadProgressCallback">Upload progress callback: the parameter indicates upload progress from 0 to 1.</param>
        /// <param name="uploadCompletedCallback">Upload completed callback: the parameter is the URL of the uploaded image.</param>
        /// <param name="uploadFailedCallback">Upload failed callback: the parameter is the error message.</param>
        public static void Upload(string username, string apiKey, GiphyUploadParams content, Action <float> uploadProgressCallback, Action <string> uploadCompletedCallback, Action <string> uploadFailedCallback)
        {
            #if !UNITY_WEBPLAYER
            if (string.IsNullOrEmpty(content.localImagePath) && string.IsNullOrEmpty(content.sourceImageUrl))
            {
                Debug.LogError("UploadToGiphy FAILED: no image was specified for uploading.");
                return;
            }
            else if (!string.IsNullOrEmpty(content.localImagePath) && !System.IO.File.Exists(content.localImagePath))
            {
                Debug.LogError("UploadToGiphy FAILED: (local) file not found.");
                return;
            }

            WWWForm form = new WWWForm();
            form.AddField("api_key", apiKey);
            form.AddField("username", username);

            if (!string.IsNullOrEmpty(content.localImagePath) && System.IO.File.Exists(content.localImagePath))
            {
                form.AddBinaryData("file", SgLib.FileUtil.ReadAllBytes(content.localImagePath));
            }

            if (!string.IsNullOrEmpty(content.sourceImageUrl))
            {
                form.AddField("source_image_url", content.sourceImageUrl);
            }

            if (!string.IsNullOrEmpty(content.tags))
            {
                form.AddField("tags", content.tags);
            }

            if (!string.IsNullOrEmpty(content.sourcePostUrl))
            {
                form.AddField("source_post_url", content.sourcePostUrl);
            }

            if (content.isHidden)
            {
                form.AddField("is_hidden", "true");
            }

            Instance.StartCoroutine(CRUpload(form, uploadProgressCallback, uploadCompletedCallback, uploadFailedCallback));
            #endif
        }
Beispiel #3
0
 public static void Upload(GiphyUploadParams content, Action <float> uploadProgressCallback, Action <string> uploadCompletedCallback, Action <string> uploadFailedCallback)
 {
     Upload("", GIPHY_PUBLIC_BETA_KEY, content, uploadProgressCallback, uploadCompletedCallback, uploadFailedCallback);
 }