-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImgBB.cs
60 lines (52 loc) · 1.83 KB
/
ImgBB.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using Newtonsoft.Json;
using SDG.Unturned;
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace ReportDiscord
{
class ImgBB
{
public static class IMGBB
{
private const string Endpoint = "https://api.imgbb.com/1/upload";
public static async Task<string> UploadAsync(byte[] data)
{
var req = WebRequest.CreateHttp(Endpoint);
req.Method = "POST";
var payload = Encoding.UTF8.GetBytes($"key={ReportDiscord.Instance.Configuration.Instance.ImgBBKey}&image={WebUtility.UrlEncode(Convert.ToBase64String(data))}&name=spy&expiration=86400");
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = payload.Length;
using (var network = await req.GetRequestStreamAsync())
{
await network.WriteAsync(payload, 0, payload.Length);
await network.FlushAsync();
}
var resp = (HttpWebResponse)await req.GetResponseAsync();
using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
{
var json = await sr.ReadToEndAsync();
var d = JsonConvert.DeserializeObject<ImgBBResult>(json);
return d.data.Display_Url;
}
}
}
public class ImgBBResult
{
public ImgBBData data;
}
public class ImgBBData
{
public string ID;
public string Title;
public string url_Viewer;
public string Url;
public string Display_Url;
public int size;
public int expiration;
public long time;
}
}
}