0

I'm trying to speed up the process of uploading file with Web Client I have wrote some code that works fine but very slow if I try to upload the same file directly from the website it would take a LOT less time any recommendation? or other libraries I should use?

static string CreateDownloadLink(string File)
{
    string ReturnValue = string.Empty;
    try
    {
        using (WebClient Client = new WebClient())
        {
            byte[] Response = Client.UploadFile("https://anonfile.com/api/upload", File);
            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;
}
smolchanovsky
  • 1,775
  • 2
  • 15
  • 29
xMoses
  • 17
  • 1
  • Possible duplicate of https://stackoverflow.com/questions/4415443/system-net-webclient-unreasonably-slow – Jon Apr 21 '19 at 13:00

1 Answers1

1

You can upload from memory using HttpWebRequest class. This looks like a faster way.

Take a look at the link below. https://web.archive.org/web/20151128202604/http://aspnetupload.com/Upload-File-POST-HttpWebRequest-WebClient-RFC-1867.aspx

Indrit Kello
  • 1,293
  • 8
  • 19