IEnumerator UploadVideo(VimeoTicket ticket) { Debug.Log("-----------------------UploadVideo-------------------------"); // Get local video file and store it in a byte array for uploading FileInfo video_file = new FileInfo(video_file_path); byte[] data = File.ReadAllBytes(video_file_path); Debug.Log(data.Length); Debug.Log(video_file.Name); // Upload to the Vimeo server Debug.Log("Uploading to " + ticket.upload_link_secure); using (UnityWebRequest request = UnityWebRequest.Put(ticket.upload_link_secure, data)) { request.SetRequestHeader("Content-Type", "video/" + video_file.Extension); yield return(request.Send()); if (request.isNetworkError) { Debug.Log(request.error); Debug.Log(request.responseCode); } else { Debug.Log(request.downloadHandler.text); Debug.Log(request.responseCode); StartCoroutine(VerifyUpload(ticket)); } } }
IEnumerator GetTicket() { if (OnUploadProgress != null) { OnUploadProgress("Authorizing", 0); } WWWForm form = new WWWForm(); form.AddField("type", "streaming"); using (UnityWebRequest request = UnityWebRequest.Post(API_URL + "/me/videos", form)) { PrepareHeaders(request, "3.2"); yield return(VimeoApi.SendRequest(request)); if (IsNetworkError(request)) { Debug.LogError(request.error); } else { VimeoTicket ticket = VimeoTicket.CreateFromJSON(request.downloadHandler.text); if (ticket.error == null) { StartCoroutine(UploadVideo(ticket)); } else { Debug.LogError(ticket.error + " " + ticket.developer_message); } } } }
IEnumerator GetTicket() { if (OnUploadProgress != null) { OnUploadProgress("Authorizing", 0); } WWWForm form = new WWWForm(); form.AddField("type", "streaming"); using (UnityWebRequest request = UnityWebRequest.Post(API_URL + "/me/videos", form)) { request.chunkedTransfer = false; request.SetRequestHeader("Authorization", "Bearer " + token); yield return(VimeoApi.SendRequest(request)); if (IsNetworkError(request)) { Debug.LogError(request.error); } else { VimeoTicket ticket = VimeoTicket.CreateFromJSON(request.downloadHandler.text); if (ticket.error == null) { StartCoroutine(UploadVideo(ticket)); } else { Debug.LogError(ticket.error); } } } }
IEnumerator CompleteUpload(VimeoTicket ticket) { Debug.Log("-----------------------CompleteUpload-------------------------"); Debug.Log("https://api.vimeo.com" + ticket.complete_uri); using (UnityWebRequest request = UnityWebRequest.Delete("https://api.vimeo.com" + ticket.complete_uri)) { request.SetRequestHeader("Authorization", "Bearer " + token); yield return(request.Send()); Debug.Log(request.responseCode); } }
IEnumerator UploadVideo(VimeoTicket ticket) { if (OnUploadProgress != null) { OnUploadProgress("Uploading", 0); } byte[] data = new byte[0]; bool success = false; // Using try/catch to wait for video to finish being while (success == false) { try { // Get local video file and store it in a byte array for uploading data = File.ReadAllBytes(video_file_path); success = true; } catch (IOException e) { // TODO: fix this ugly code! Debug.Log("File is being accessed by another process. " + e.Message); } } FileInfo video_file = new FileInfo(video_file_path); // Upload to the Vimeo server using (UnityWebRequest request = UnityWebRequest.Put(ticket.upload_link_secure, data)) { uploader = request; request.chunkedTransfer = false; request.SetRequestHeader("Content-Type", "video/" + video_file.Extension); yield return(VimeoApi.SendRequest(request)); uploader = null; if (IsNetworkError(request)) { if (OnNetworkError != null) { OnNetworkError(request.error); } } else { StartCoroutine(VerifyUpload(ticket)); } } }
IEnumerator CompleteUpload(VimeoTicket ticket) { Debug.Log("-----------------------CompleteUpload-------------------------"); Debug.Log(API_URL + ticket.complete_uri); using (UnityWebRequest request = UnityWebRequest.Delete(API_URL + ticket.complete_uri)) { request.SetRequestHeader("Authorization", "Bearer " + token); yield return(request.Send()); if (OnUploadComplete != null) { OnUploadComplete(request.GetResponseHeader("Location")); } } }
IEnumerator CompleteUpload(VimeoTicket ticket) { if (OnUploadProgress != null) { OnUploadProgress("Complete", 1f); } using (UnityWebRequest request = UnityWebRequest.Delete(API_URL + ticket.complete_uri)) { PrepareHeaders(request); yield return(VimeoApi.SendRequest(request)); if (OnUploadComplete != null) { OnUploadComplete(request.GetResponseHeader("Location")); } } }
IEnumerator CompleteUpload(VimeoTicket ticket) { if (OnUploadProgress != null) { OnUploadProgress("Complete", 1f); } // Debug.Log (API_URL + ticket.complete_uri); using (UnityWebRequest request = UnityWebRequest.Delete(API_URL + ticket.complete_uri)) { request.chunkedTransfer = false; request.SetRequestHeader("Authorization", "Bearer " + token); yield return(VimeoApi.SendRequest(request)); if (OnUploadComplete != null) { OnUploadComplete(request.GetResponseHeader("Location")); } } }
IEnumerator VerifyUpload(VimeoTicket ticket) { Debug.Log("-----------------------VerifyUpload-------------------------"); byte[] data = new byte[] { 0x00 }; using (UnityWebRequest request = UnityWebRequest.Put(ticket.upload_link_secure, data)) { request.SetRequestHeader("Content-Range", "bytes */*"); yield return(request.Send()); if (request.responseCode == 308) { //Debug.Log ("Verified!!"); //Debug.Log (request.GetResponseHeader ("Range")); Debug.Log(request.downloadHandler.text); StartCoroutine(CompleteUpload(ticket)); } else { Debug.Log(request.responseCode); } } }
IEnumerator VerifyUpload(VimeoTicket ticket) { if (OnUploadProgress != null) { OnUploadProgress("Verifying", 0.9999999f); } byte[] data = new byte[] { 0x00 }; using (UnityWebRequest request = UnityWebRequest.Put(ticket.upload_link_secure, data)) { request.chunkedTransfer = false; request.SetRequestHeader("Content-Range", "bytes */*"); yield return(VimeoApi.SendRequest(request)); if (request.responseCode == 308) { StartCoroutine(CompleteUpload(ticket)); } else { Debug.Log(request.responseCode); } } }
IEnumerator GetTicket() { WWWForm form = new WWWForm(); form.AddField("type", "streaming"); using (UnityWebRequest request = UnityWebRequest.Post("https://api.vimeo.com/me/videos", form)) { request.SetRequestHeader("Authorization", "Bearer " + token); yield return(request.Send()); if (request.isNetworkError) { Debug.Log(request.error); } else { Debug.Log(request.downloadHandler.text); VimeoTicket ticket = VimeoTicket.CreateFromJSON(request.downloadHandler.text); //Debug.Log (ticket.ticket_id); StartCoroutine(UploadVideo(ticket)); } } }