Last active
October 3, 2021 02:53
-
-
Save andrewpisula/820960892b8c533a7d8e7ce9edde64dc to your computer and use it in GitHub Desktop.
C# Function to upload a file to anonfile.com
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
static string CreateDownloadLink(string File) // Important to note AnonFile has a 20gb file size limit (which is overkill for most applications) | |
{ | |
string ReturnValue = string.Empty; | |
try | |
{ | |
using (WebClient Client = new WebClient()) | |
{ | |
byte[] Response = Client.UploadFile("https://api.anonfiles.com/upload", File);// Thanks noobencoder for pointing out that Anonfile changed domains since when I originally wrote this 3 years ago. It's fixed now. | |
string ResponseBody = Encoding.ASCII.GetString(Response); | |
if (ResponseBody.Contains("\"error\": {")) | |
{ | |
ReturnValue += "There was a erorr while uploading the file.\r\n"; | |
ReturnValue += "Error message: " + ResponseBody.Split('"')[7] + "\r\n"; | |
} | |
else | |
{ | |
ReturnValue += "Download link: " + ResponseBody.Split('"')[15] + "\r\n"; | |
ReturnValue += "File name: " + ResponseBody.Split('"')[25] + "\r\n"; | |
} | |
} | |
} | |
catch (Exception Exception) | |
{ | |
ReturnValue += "Exception Message:\r\n" + Exception.Message + "\r\n"; | |
} | |
return ReturnValue; | |
} |
akinciemre
commented
Oct 11, 2020
•
static string CreateDownloadLink(string File) { string ReturnValue = string.Empty; try { using (WebClient Client = new WebClient()) { byte[] Response = Client.UploadFile("https://api.anonfiles.com/upload", File); //Edited (Working*) string ResponseBody = Encoding.ASCII.GetString(Response); if (ResponseBody.Contains("\"error\": {")) { ReturnValue += "There was a erorr while uploading the file.\r\n"; ReturnValue += "Error message: " + ResponseBody.Split('"')[7] + "\r\n"; } else { ReturnValue += "Download link: " + ResponseBody.Split('"')[15] + "\r\n"; ReturnValue += "File name: " + ResponseBody.Split('"')[25] + "\r\n"; } } } catch (Exception Exception) { ReturnValue += "Exception Message:\r\n" + Exception.Message + "\r\n"; } return ReturnValue; }
Thank you, I'll make sure to update my gist with the proper URL
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment