// Note that this event is invoked on a background thread, so we cannot access the UI directly. private void UploadProgress(UploadOperation upload) { // UploadOperation.Progress is updated in real-time while the operation is ongoing. Therefore, // we must make a local copy so that we can have a consistent view of that ever-changing state // throughout this method's lifetime. BackgroundUploadProgress currentProgress = upload.Progress; MarshalLog(String.Format(CultureInfo.CurrentCulture, "Progress: {0}, Status: {1}", upload.Guid, currentProgress.Status)); double percentSent = 100; if (currentProgress.TotalBytesToSend > 0) { percentSent = currentProgress.BytesSent * 100 / currentProgress.TotalBytesToSend; } MarshalLog(String.Format(CultureInfo.CurrentCulture, " - Sent bytes: {0} of {1} ({2}%), Received bytes: {3} of {4}", currentProgress.BytesSent, currentProgress.TotalBytesToSend, percentSent, currentProgress.BytesReceived, currentProgress.TotalBytesToReceive)); if (currentProgress.HasRestarted) { MarshalLog(" - Upload restarted"); } if (currentProgress.HasResponseChanged) { // We've received new response headers from the server. MarshalLog(" - Response updated; Header count: " + upload.GetResponseInformation().Headers.Count); // If you want to stream the response data this is a good time to start. // upload.GetResultStreamAt(0); } }
/// <summary> /// Event is invoked on a background thread. /// </summary> /// <param name="upload">UploadOperation.</param> private void UploadProgress(UploadOperation upload) { // Progress: upload.Guid; Statues: uplaod.Progress.Status BackgroundUploadProgress progress = upload.Progress; double percentSend = 100; if (progress.TotalBytesToSend > 0) { percentSend = progress.BytesSent * 100 / progress.TotalBytesToSend; } // Send bytes: progress.BytesSend of progress.TotalBytesSend (percentSend%) // Received bytes: progress.BytesReceived of progress.TotalBytesToReceive if (progress.HasRestarted) { // Upload restarted System.Diagnostics.Debug.WriteLine("Upload restarted"); } if (progress.HasResponseChanged) { // Response updated; Header count: upload.GetResponseInformation().Headers.Count } }
// Note that this event is invoked on a background thread, so we cannot access the UI directly. private void UploadProgress(UploadOperation upload) { // UploadOperation.Progress is updated in real-time while the operation is ongoing. Therefore, // we must make a local copy so that we can have a consistent view of that ever-changing state // throughout this method's lifetime. BackgroundUploadProgress currentProgress = upload.Progress; double percentSent = 100; if (currentProgress.TotalBytesToSend > 0) { percentSent = currentProgress.BytesSent * 100 / currentProgress.TotalBytesToSend; } var fileUploadProgress = new FileUploadProgress((long)currentProgress.BytesSent, (long)currentProgress.TotalBytesToSend, upload.TransferGroup.Name); FileUploadProgress(this, fileUploadProgress); if (currentProgress.HasRestarted) { // MarshalLog(" - Upload restarted"); } if (currentProgress.HasResponseChanged) { // We've received new response headers from the server. // If you want to stream the response data this is a good time to start. //upload.GetResultStreamAt(0); } }
// Note that this event is invoked on a background thread, so we cannot access the UI directly. private void UploadProgress(UploadOperation upload) { MarshalLog(String.Format(CultureInfo.CurrentCulture, "Progress: {0}, Status: {1}", upload.Guid, upload.Progress.Status)); BackgroundUploadProgress progress = upload.Progress; double percentSent = 100; if (progress.TotalBytesToSend > 0) { percentSent = progress.BytesSent * 100 / progress.TotalBytesToSend; } MarshalLog(String.Format(CultureInfo.CurrentCulture, " - Sent bytes: {0} of {1} ({2}%), Received bytes: {3} of {4}", progress.BytesSent, progress.TotalBytesToSend, percentSent, progress.BytesReceived, progress.TotalBytesToReceive)); if (progress.HasRestarted) { MarshalLog(" - Upload restarted"); } if (progress.HasResponseChanged) { // We've received new response headers from the server. MarshalLog(" - Response updated; Header count: " + upload.GetResponseInformation().Headers.Count); // If you want to stream the response data this is a good time to start. upload.GetResultStreamAt(0); } }
// Note that this event is invoked on a background thread, so we cannot access the UI directly. private void UploadProgress(UploadOperation upload) { BackgroundUploadProgress _progress = upload.Progress; if (_progress.HasRestarted) { MarshalProgress(" - Upload restarted", 0); } else if (_progress.HasResponseChanged) { // We've received new response headers from the server. MarshalProgress(" - Response updated; Header count: " + upload.GetResponseInformation().Headers.Count, 0); // If you want to stream the response data this is a good time to start. // upload.GetResultStreamAt(0); } else { int _percent = 100; if (_progress.TotalBytesToSend > 0) { _percent = (int)(_progress.BytesSent * 100 / _progress.TotalBytesToSend); } float _sent = _progress.BytesSent / 1000000; float _total = _progress.TotalBytesToSend / 1000000; MarshalProgress(String.Format(CultureInfo.CurrentCulture, " Upload {0}: {1}MB of {2}MB", _progress.Status.ToString().ToLower(), _sent.ToString(), _total.ToString()), _percent); } }
async void UploadProgress(UploadOperation upload) { LogStatus(string.Format("Progress: {0}, Status: {1}", upload.Guid, upload.Progress.Status)); BackgroundUploadProgress progress = upload.Progress; double percentSent = 100; if (progress.TotalBytesToSend > 0) { var bs = progress.BytesSent; percentSent = bs * 100 / progress.TotalBytesToSend; } SendNotify(percentSent); //MarshalLog(String.Format(" - Sent bytes: {0} of {1} ({2}%)", // progress.BytesSent, progress.TotalBytesToSend, percentSent)); LogStatus(string.Format(" - Sent bytes: {0} of {1} ({2}%), Received bytes: {3} of {4}", progress.BytesSent, progress.TotalBytesToSend, percentSent, progress.BytesReceived, progress.TotalBytesToReceive)); if (progress.HasRestarted) { LogStatus(" - Upload restarted"); } if (progress.HasResponseChanged) { var resp = upload.GetResponseInformation(); // We've received new response headers from the server. LogStatus(" - Response updated; Header count: " + resp.Headers.Count); var response = upload.GetResultStreamAt(0); StreamReader stream = new StreamReader(response.AsStreamForRead()); Debug.WriteLine("----------------------------------------Response from upload----------------------------------"); var st = stream.ReadToEnd(); Debug.WriteLine(st); //var res = JsonConvert.DeserializeObject<APIResponseOverride>(st); //await ConfigureMediaPhotoAsync(res.upload_id, Caption, null, null); await FinishVoiceAsync(); //UploadCompleted?.Invoke(null, Convert.ToInt64(res.upload_id)); // If you want to stream the response data this is a good time to start. // upload.GetResultStreamAt(0); } }
/// <summary> /// This is the progress changed event which will return progress. /// </summary> /// <param name="upload"></param> private static void UploadProgress(UploadOperation upload) { BackgroundUploadProgress progress = upload.Progress; double percentSent = 100; if (progress.TotalBytesToSend > 0) { percentSent = progress.BytesSent * 100 / progress.TotalBytesToSend; if (OnUploadProgressChanged != null) { OnUploadProgressChanged(percentSent, (double)progress.BytesSent, (double)progress.TotalBytesToSend); } } //pbProgress.Value = percentSent; //tblockPercentageDownloaded.Text = percentSent + "%"; }
private void UploadProgress(UploadOperation upload) { BackgroundUploadProgress progress = upload.Progress; double percentSent = 100; if (progress.TotalBytesToSend > 0) { percentSent = progress.BytesSent * 100 / progress.TotalBytesToSend; if (this.GetPercent != null) { this.GetPercent((long)percentSent, (long)progress.TotalBytesToSend); } } if (progress.BytesSent == progress.TotalBytesToSend) { if (this.FinishHandler != null) { this.FinishHandler(this, "Finish"); } } }
// Note that this event is invoked on a background thread, so we cannot access the UI directly. private void UploadProgress(UploadOperation upload) { BackgroundUploadProgress progress = upload.Progress; double percentSent = 100; if (progress.TotalBytesToSend > 0) { percentSent = progress.BytesSent * 100 / progress.TotalBytesToSend; } if (progress.Status == BackgroundTransferStatus.Completed) { XmlDocument toastXML = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); XmlNodeList texts = toastXML.GetElementsByTagName("text"); texts[0].AppendChild(toastXML.CreateTextNode("HAP+ - Upload Complete")); texts[1].AppendChild(toastXML.CreateTextNode("The uploading of " + upload.SourceFile.Name + " has completed.")); ((XmlElement)toastXML.SelectSingleNode("/toast")).SetAttribute("launch", "{\"type\":\"toast\"}"); ToastNotification toast = new ToastNotification(toastXML); ToastNotificationManager.CreateToastNotifier().Show(toast); } }
async void UploadProgress(UploadOperation upload) { LogStatus(string.Format("Progress: {0}, Status: {1}", upload.Guid, upload.Progress.Status)); MainPage.Current?.ShowMediaUploadingUc(); BackgroundUploadProgress progress = upload.Progress; double percentSent = 100; if (progress.TotalBytesToSend > 0) { percentSent = progress.BytesSent * 100 / progress.TotalBytesToSend; } SendNotify(percentSent); LogStatus(string.Format(" - Sent bytes: {0} of {1} ({2}%), Received bytes: {3} of {4}", progress.BytesSent, progress.TotalBytesToSend, percentSent, progress.BytesReceived, progress.TotalBytesToReceive)); if (progress.HasRestarted) { LogStatus(" - Upload restarted"); } if (progress.HasResponseChanged) { var resp = upload.GetResponseInformation(); LogStatus(" - Response updated; Header count: " + resp.Headers.Count); var response = upload.GetResultStreamAt(0); StreamReader stream = new StreamReader(response.AsStreamForRead()); Debug.WriteLine("----------------------------------------Response from upload----------------------------------"); var st = stream.ReadToEnd(); Debug.WriteLine(st); if (UploadItem.IsVideo) { if (!UploadItem.IsStory) { var thumbStream = (await UploadItem.ImageToUpload.OpenAsync(FileAccessMode.Read)).AsStream(); var bytes = await thumbStream.ToByteArray(); var img = new InstaImageUpload { ImageBytes = bytes, Uri = UploadItem.ImageToUpload.Path }; await UploadSinglePhoto(img, UploadId); } await Task.Delay(15000); if (!UploadItem.IsStory) { await FinishVideoAsync(); } await Task.Delay(1500); } if (!UploadItem.IsAlbum) { await ConfigurMediaAsync(); } else { OnUploadCompleted?.Invoke(this); } } }