public static Ticket FromJson(JSONNode json) { Ticket ticket = new Ticket(); ticket.Uri = json["uri"].Value; ticket.CompleteUri = json["complete_uri"].Value; ticket.TicketId = json["ticket_id"].Value; ticket.UploadLinkSecure = json["upload_link_secure"].Value; return ticket; }
public string Upload(string path, Ticket ticket = null, int chunkSize = Core.DEFAULT_CHUNK_SIZE, int maxAttempts = Core.DEFAULT_MAX_ATTEMPTS, long startByte = 0, bool step = false) { int attempts = 0; if (ticket == null) ticket = GetTicket(); long contentLength = new FileInfo(path).Length; while (true) { var feedback = Verify(ticket.UploadLinkSecure); startByte = feedback.LastByte; feedback.ContentSize = contentLength; if (VerboseCallback != null) VerboseCallback(String.Format("{0}/{1} Uploaded.", feedback.LastByte, contentLength)); if (UploadCallback != null) UploadCallback(feedback); if (feedback.LastByte >= contentLength) { Debug.WriteLine("Done!"); break; } try { var payload = Core.GetPayload(path, startByte, chunkSize); Upload(ticket.UploadLinkSecure, contentLength, startByte, payload); } catch (Exception e) { attempts++; if (attempts > maxAttempts) { Debug.WriteLine(e.Message, "Upload"); return null; } } if (step) return ""; } var complete = Complete(apiRoot + ticket.CompleteUri, new WebHeaderCollection() { { "Authorization", String.Format("Bearer {0}", AccessToken) } }); return complete; }