Exemple #1
0
        public async Task <ImgurImage> UploadImage(Image image)
        {
            try
            {
                string base64Image = "";
                using (var m = new MemoryStream())
                {
                    image.Save(m, image.RawFormat);
                    byte[] imageBytes = m.ToArray();
                    base64Image = Convert.ToBase64String(imageBytes);
                }

                var values = new NameValueCollection
                {
                    { "image", base64Image },
                    { "type", "base64" }
                };

                byte[] res = null;
                await Task.Run(() =>
                {
                    var client = new AskMonaWrapper.WebClientWithTimeout();
                    client.Headers.Add("Authorization", "Client-ID " + mClientId);
                    res = client.UploadValues(mApiBaseUrl + "image", "POST", values);
                });

                var serializer      = new DataContractJsonSerializer(typeof(ImgurRootObject <ImgurImage>));
                var imgurRootObject = (ImgurRootObject <ImgurImage>)serializer.ReadObject(new MemoryStream(res));
                return(imgurRootObject.Data);
            }
            catch
            {
                return(null);
            }
        }
Exemple #2
0
        public async Task <bool> DeleteImage(string deleteHash)
        {
            try
            {
                byte[] res = null;
                await Task.Run(() =>
                {
                    var client = new AskMonaWrapper.WebClientWithTimeout();
                    client.Headers.Add("Authorization", "Client-ID " + mClientId);
                    res = client.UploadValues(mApiBaseUrl + "image/" + deleteHash, "DELETE", new NameValueCollection());
                });

                var serializer      = new DataContractJsonSerializer(typeof(ImgurRootObject <bool>));
                var imgurRootObject = (ImgurRootObject <bool>)serializer.ReadObject(new MemoryStream(res));
                return(imgurRootObject.Data);
            }
            catch
            {
                return(false);
            }
        }