示例#1
0
        private UnityWebRequestAsyncOperation _uploadAttachment(string path, RefAndMethod uploadLink)
        {
            var filename = Path.GetFileName(path);

            byte[] data = File.ReadAllBytes(path);
            return(_uploadFile(filename, data, uploadLink));
        }
示例#2
0
        private void _uploadAttachments(Report report, RefAndMethod uploadLink)
        {
            foreach (var texture in report.screenshots)
            {
                UnityWebRequestAsyncOperation wwwOp = _uploadScreenshot(texture, uploadLink);

                if (_isVerbose)
                {
                    wwwOp.completed += (AsyncOperation op) =>
                    {
                        var uwrOp = (UnityWebRequestAsyncOperation)op;
                        var www   = uwrOp.webRequest;
                        Debug.Log($"Upload attachment response: {www.downloadHandler.text}");
                    };
                }
            }
            foreach (var filename in report.attachments)
            {
                UnityWebRequestAsyncOperation wwwOp = _uploadAttachment(filename, uploadLink);

                if (_isVerbose)
                {
                    wwwOp.completed += (AsyncOperation op) =>
                    {
                        var uwrOp = (UnityWebRequestAsyncOperation)op;
                        var www   = uwrOp.webRequest;
                        Debug.Log($"Upload attachment response: {www.downloadHandler.text}");
                    };
                }
            }
        }
示例#3
0
        private UnityWebRequestAsyncOperation _uploadFile(string filename, byte[] data, RefAndMethod uploadLink)
        {
            List <IMultipartFormSection> formData = new List <IMultipartFormSection>();

            formData.Add(new MultipartFormFileSection("attachment_file", data, filename, ""));

            APIProperties apiProperties = new APIProperties(_connectionURI);
            var           href          = new Uri(uploadLink.href, UriKind.Relative);
            var           builder       = new Uri(apiProperties.BaseURI.Uri, href);
            var           www           = UnityWebRequest.Post(builder.ToString(), formData);

            // 60 Seconds timeout.
            www.timeout         = 60;
            www.downloadHandler = new DownloadHandlerBuffer();
            UnityWebRequestAsyncOperation wwwOp = www.SendWebRequest();

            return(wwwOp);
        }
示例#4
0
 private UnityWebRequestAsyncOperation _uploadScreenshot(Texture2D texture, RefAndMethod uploadLink)
 {
     byte[] data = texture.EncodeToJPG();
     return(_uploadFile(texture.name, data, uploadLink));
 }