public static IEnumerator UploadScreenShot(UploadData data, Action onSuccess = null, Action <string> onError = null) { yield return(new WaitForSeconds(0.1f)); List <IMultipartFormSection> formData = new List <IMultipartFormSection>(); byte[] contents = data.ScreenShot.EncodeToPNG(); formData.Add(new MultipartFormDataSection("token", data.Token)); formData.Add(new MultipartFormDataSection("title", data.Title)); formData.Add(new MultipartFormDataSection("initial_comment", data.InitialComment)); formData.Add(new MultipartFormDataSection("channels", data.Channels)); formData.Add(new MultipartFormFileSection("file", contents, data.Filename, "image/png")); UnityWebRequest www = UnityWebRequest.Post($"{apiUrl}/files.upload", formData); yield return(www.SendWebRequest());; string error = www.error; if (!string.IsNullOrEmpty(error)) { if (onError != null) { onError(error); } yield break; } if (onSuccess != null) { onSuccess(); } }
public static IEnumerator UploadScreenShot(UploadData data, Action onSuccess = null, Action <string> onError = null) { yield return(new WaitForSeconds(0.1f)); var form = new WWWForm(); var contents = data.screenShot.EncodeToPNG(); form.AddField("token", data.token); form.AddField("title", data.title); form.AddField("initial_comment", data.initial_comment); form.AddField("channels", data.channels); form.AddBinaryData("file", contents, data.filename, "image/png"); var url = "https://slack.com/api/files.upload"; var www = new WWW(url, form); yield return(www); var error = www.error; if (!string.IsNullOrEmpty(error)) { if (onError != null) { onError(error); } yield break; } if (onSuccess != null) { onSuccess(); } }
private IEnumerator CaptureToSlack() { if (!SettingData.IsCompletedSlackData()) { yield break; } _fileName = DateTime.Now.ToString("yyyyMMddHHmmss"); filePath = $"{SettingData.BackupPath}/{_fileName}.png"; yield return(EditorCoroutines.EditorCoroutines.StartCoroutine(CaptureGameView(filePath), this)); var uploadData = new SlackHelper.UploadData { Token = SettingData.SlackToken, Title = SettingData.SlackTitle, InitialComment = SettingData.SlackComment, Filename = _fileName, Channels = SettingData.SlackChannelName, }; _screenshot = new Texture2D(1, 1); byte[] bytes = System.IO.File.ReadAllBytes(filePath); _screenshot.LoadImage(bytes); uploadData.ScreenShot = _screenshot; yield return(EditorCoroutines.EditorCoroutines.StartCoroutine(SlackHelper.SlackHelper.UploadScreenShot(uploadData, OnSuccess, OnError), this)); }