Created
April 27, 2020 17:32
-
-
Save ihorbond/05b4e6edfc2f90a238a5534fd9791663 to your computer and use it in GitHub Desktop.
Upload file anonymously with C#
This file contains 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
private static async Task<string> UploadFile(byte[] bytes, string expiresParam = "1d", bool noIndexParam = true) | |
{ | |
string res = null; | |
try | |
{ | |
using (var client = new HttpClient()) | |
using (var formData = new MultipartFormDataContent()) | |
{ | |
formData.Add(new StringContent(noIndexParam.ToString()), "no_index"); | |
formData.Add(new StringContent(expiresParam), "expires"); | |
formData.Add(new ByteArrayContent(bytes), "file", Guid.NewGuid().ToString()); | |
HttpResponseMessage response = await client.PostAsync("https://api.anonymousfiles.io/", formData); | |
if (response.IsSuccessStatusCode) | |
return await response.Content.ReadAsStringAsync(); | |
} | |
} | |
catch (Exception ex) | |
{ | |
//handle ex | |
} | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment