Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I need to upload a file to virus checking site using this code

C#
public string Scan(string file)
{
    var v = new NameValueCollection();
    v.Add("key", APIKey);
    var c = new MyWebClient() { QueryString = v };
    
    c.Headers.Add("Content-type", "binary/octet-stream");
    ServicePointManager.SecurityProtocol = (SecurityProtocolType)768 | (SecurityProtocolType)3072;
    byte[] b = c.UploadFile(scan, "POST", file);
    string json = Encoding.Default.GetString(b);
    var r = ParseJSON(json);
    if (r.ContainsKey("scan_id"))
    {
        return r["scan_id"];
    }
    throw new Exception(r["result"]);
}
This code works fine with smaller files, but once I try to upload files of 50 MB size I get the exception

The remote server returned an error: (413) Request Entity Too Large.

I did lookup this error and tried increase the maxAllowedContentLength and maxRequestLength values to 2147483647

It didn't help. No matter what I do, I always get the error mentioned above

Is there any way to upload the large file to a site using the WebClient class? Is there any other way to upload the larger file in the ASP.NET Web Forms?

Thank you very much in advance

What I have tried:

I did lookup this error and tried increase the maxAllowedContentLength and maxRequestLength values to 2147483647
Posted

1 solution

The error message is pretty explicit. The server is configured to only allow uploads that are under 50MB. You cannot do anything about that in your code.

If you don't control the server code and configuration, there is nothing you can do to fix this problem.
 
Share this answer
 
Comments
Member 13304618 6-Feb-24 21:23pm    
Thank you very much

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900