Skip to content

Instantly share code, notes, and snippets.

@ihorbond
Created April 27, 2020 17:32
Show Gist options
  • Save ihorbond/05b4e6edfc2f90a238a5534fd9791663 to your computer and use it in GitHub Desktop.
Save ihorbond/05b4e6edfc2f90a238a5534fd9791663 to your computer and use it in GitHub Desktop.
Upload file anonymously with C#
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