//Upload Image to Imgur and returns URL to Imgur private async Task <string> UploadImgur(byte[] cimg, string WindowName) { string response = await _imgur.Upload(cimg, WindowName); //Copy Link to Clipboard Clipboard.SetText(response); return(response); }
private async void InstantUpload(List <string> files) { await Task.Delay(550); if (files.Count > 1) { //////UPLOAD MULTIPLE IMAGES try { //Binary Image List <byte[]> images = new List <byte[]>(); //Image IDs double size = 0; foreach (string file in files) { byte[] image = File.ReadAllBytes(file); images.Add(image); size += image.Length; } //Image Size string kb = $"{size / 1024d:0.#}"; //Key = Album ID | Value = Album Delete Hash (Key = Value if User is logged in) KeyValuePair <string, string> albumInfo = await _imgur.CreateAlbum(); Notification = new Notification("", Notification.NotificationType.Progress, false, null); Notification.Show(); int index = 1; //Upload each image for (int i = 0; i < images.Count; i++) { try { //e.g. "Uploading Images (123KB) (1 of 2)" //SuccessToast.Show(string.Format(strings.uploadingFiles, kb, index, files.Count), TimeSpan.FromDays(10)); Notification.contentLabel.Text = string.Format(strings.uploadingFiles, kb, index, files.Count); } catch (Exception e) { Debug.Write(e.Message); //this image was not uploaded } index++; } await OpenAlbum(albumInfo.Key); Notification.Close(); } catch { //Unsupported File Type? Internet connection error? Notification = new Notification(strings.errorInstantUpload, Notification.NotificationType.Error, true, ActionTroubleshoot); await Notification.ShowAsync(); //await ErrorToast.ShowAsync(strings.errorInstantUpload, TimeSpan.FromSeconds(5)); } } else { //////UPLOAD SINGLE IMAGE try { //Binary Image byte[] byteImg = File.ReadAllBytes(files[0]); //Image Size string kb = $"{byteImg.Length / 1024d:0.#}"; //e.g. "Uploading Image (123KB)" Notification = new Notification(string.Format(strings.uploading, kb), Notification.NotificationType.Progress, false, null); Notification.Show(); //SuccessToast.Show(string.Format(strings.uploading, kb), TimeSpan.FromDays(10)); string link = await _imgur.Upload(byteImg, ""); await HandleLink(link); Notification.Close(); } catch { //Unsupported File Type? Internet connection error? Notification = new Notification(strings.errorInstantUpload, Notification.NotificationType.Error, true, ActionTroubleshoot); await Notification.ShowAsync(); //await ErrorToast.ShowAsync(strings.errorInstantUpload, TimeSpan.FromSeconds(5)); } } DelayedClose(0); }