Skip to content

Instantly share code, notes, and snippets.

@andrewpisula
Last active October 3, 2021 02:53
Show Gist options
  • Save andrewpisula/820960892b8c533a7d8e7ce9edde64dc to your computer and use it in GitHub Desktop.
Save andrewpisula/820960892b8c533a7d8e7ce9edde64dc to your computer and use it in GitHub Desktop.
C# Function to upload a file to anonfile.com
@andrewpisula
Copy link
Author

andrewpisula commented Oct 3, 2021

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