I copy without problem small file. When users try to upload a file of big dimension (I guess > 60MB) I got into a web Exception (404 Not Found).
I'm pretty sure that the problem is due to the file size. I got exception at
webRequest.GetResponse()
Do I need modification server side? Any suggestion is appreciate.
public static bool UploadFile(IResult result, string pathFile, Stream stream)
{
// upload effettivo del file su DB
HttpWebRequest webRequest = WebRequest.Create(ClientCommon.Properties.Settings.Default.FileServiceURI) as HttpWebRequest;
HttpWebResponse response = null;
Stream s = null;
try
{
webRequest.Method = WebRequestMethods.Http.Post;
webRequest.Credentials = CredentialCache.DefaultCredentials;
webRequest.KeepAlive = true;
using (WebRequestBuilder wrb = new WebRequestBuilder())
{
webRequest.ContentType = wrb.ContentType;
wrb.AddTextPart("cdFile", pathFile);
wrb.AddFilePart("file", stream);
wrb.AddTextPart("destination", pathFile);
if (wrb.GetContent(result, out s) == false)
return false;
s.CopyTo(webRequest.GetRequestStream());
}
response = webRequest.GetResponse() as HttpWebResponse;
return true;
}
catch (WebException exc)
{
result.SetError(exc.Message);
return false;
}
finally
{
if (response != null)
response.Close();
if (s != null)
// When the above code has ended, close the streams
s.Close();
}
}
Try to add below code in your web.config
.
<system.web>
<!-- Your other settings here -->
<httpRuntime targetFramework="Your Framework" maxRequestLength="2147483647" />
</system.web>
<system.webServer>
<!-- Your other settings here -->
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>
</system.webServer>
maxRequestLength: The property maxRequestLength indicates the maximum file upload size supported by ASP.NET. This limit can be used to prevent denial of service attacks caused by users posting large files to the server. The size specified is in kilobytes. The default is 4096 KB (4 MB). Here you can read more about maxRequestLength
.
maxAllowedContentLength: Specifies limits on requests processed by the Web server. Here you can read more about maxAllowedContentLength
.
By above code you can receive file upto 2GB length. you may modify it by yours need