private async void UploadImage(UIImage img) { var hud = new CodeHub.iOS.Utilities.Hud(null); hud.Show("Uploading..."); try { var returnData = await Task.Run <byte[]>(() => { using (var w = new WebClient()) { var data = img.AsJPEG(); byte[] dataBytes = new byte[data.Length]; System.Runtime.InteropServices.Marshal.Copy(data.Bytes, dataBytes, 0, Convert.ToInt32(data.Length)); w.Headers.Set("Authorization", "Client-ID aa5d7d0bc1dffa6"); var values = new NameValueCollection { { "image", Convert.ToBase64String(dataBytes) } }; return(w.UploadValues("https://api.imgur.com/3/image", values)); } }); var json = Mvx.Resolve <IJsonSerializationService>(); var imgurModel = json.Deserialize <ImgurModel>(System.Text.Encoding.UTF8.GetString(returnData)); TextView.InsertText("![](" + imgurModel.Data.Link + ")"); } catch (Exception e) { AlertDialogService.ShowAlert("Error", "Unable to upload image: " + e.Message); } finally { hud.Hide(); } }
private async void UploadImage(UIImage img) { var hud = new CodeHub.iOS.Utilities.Hud(null); hud.Show("Uploading..."); try { var returnData = await Task.Run<byte[]>(() => { using (var w = new WebClient()) { var data = img.AsJPEG(); byte[] dataBytes = new byte[data.Length]; System.Runtime.InteropServices.Marshal.Copy(data.Bytes, dataBytes, 0, Convert.ToInt32(data.Length)); w.Headers.Set("Authorization", "Client-ID aa5d7d0bc1dffa6"); var values = new NameValueCollection { { "image", Convert.ToBase64String(dataBytes) } }; return w.UploadValues("https://api.imgur.com/3/image", values); } }); var json = Mvx.Resolve<IJsonSerializationService>(); var imgurModel = json.Deserialize<ImgurModel>(System.Text.Encoding.UTF8.GetString(returnData)); TextView.InsertText("![](" + imgurModel.Data.Link + ")"); } catch (Exception e) { AlertDialogService.ShowAlert("Error", "Unable to upload image: " + e.Message); } finally { hud.Hide(); } }