Advertisement
Guest User

ImgBBExtension

a guest
Oct 15th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using System.Net;
  2. using System.Text;
  3. using Newtonsoft.Json.Linq;
  4. using System.Collections.Specialized;
  5.  
  6. namespace MyShop.Tools
  7. {
  8.     public class ImgBBExtension
  9.     {
  10.         private static readonly string _apiKey = "507d546dd56ee58e4da9ce88*********";
  11.         private static readonly string _apiUrl = "https://api.imgbb.com/1/upload";
  12.  
  13.         public static string UploadImage(string imageBase64Data)
  14.         {
  15.             using (WebClient client = new WebClient())
  16.             {
  17.                 NameValueCollection param = new NameValueCollection();
  18.                 param.Add("key", _apiKey);
  19.                 param.Add("image", imageBase64Data);
  20.  
  21.                 var response = client.UploadValues(_apiUrl, "POST", param);
  22.                 var result = Encoding.UTF8.GetString(response);
  23.  
  24.                 var json = JObject.Parse(result);
  25.                 var imageUrl = (string) json["data"]["url"];
  26.  
  27.                 return imageUrl;
  28.             }
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement