Ejemplo n.º 1
0
        public void UploadImg(IMG img)
        {
            using (var w = new WebClient())
            {
                if (img.Path != IMG.GetIMG(img.ID).Path)
                {
                    string clientID = "f928822a72eebbe";
                    w.Headers.Add("Authorization", "Client-ID " + clientID);
                    var values = new NameValueCollection
                    {
                        { "image", Convert.ToBase64String(System.IO.File.ReadAllBytes(img.Path)) }
                    };

                    byte[]    response = w.UploadValues("https://api.imgur.com/3/upload.xml", values);
                    XDocument data     = XDocument.Load(new MemoryStream(response));
                    string    imgPath  = data.Root.Elements().Last().Value;

                    img.Path = imgPath;
                    IMG.Update(img);
                }
            }
        }