Created
September 10, 2019 06:34
-
-
Save Kukks/21d86f51b6e5b62efeb7a314c728a6ed to your computer and use it in GitHub Desktop.
Imgur anon upload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task UploadScreenshot(string clientId) | |
{ | |
Screenshot ss = ((ITakesScreenshot) Driver).GetScreenshot(); | |
var link = await UploadImageAnonymous(ss.AsBase64EncodedString, $"btcpayservertests_{DateTime.Now}"); | |
Logs.Tester.LogInformation($"screenshot uploaded to {link}"); | |
} | |
private async Task<string> UploadImageAnonymous(string base64, string name,string clientId) | |
{ | |
string baseUrl = "https://api.imgur.com/3/"; | |
using (HttpClient client = new HttpClient()) | |
{ | |
client.DefaultRequestHeaders.Add("Authorization", "Client-ID " + clientId); | |
var jsonData = JsonConvert.SerializeObject(new | |
{ | |
image = base64, | |
name | |
}); | |
var jsonContent = new StringContent(jsonData, Encoding.UTF8, "application/json"); | |
var response = await client.PostAsync(new Uri(baseUrl + "upload"), jsonContent); | |
return response.IsSuccessStatusCode ? JObject.Parse(await response.Content.ReadAsStringAsync())["data"]["link"].ToString() : string.Empty; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment