I am trying to send large excel file to the rest service ( using servicestack).
client and server(Servicestack service) applications are deployed on different server.
I am using following code at client side to upload the excel file ( 8 mb size)
taken from
http://www.codeproject.com/Articles/501608/Sending-Stream-to-ServiceStack
HttpWebRequest client = (HttpWebRequest)WebRequest
.Create(ConfigurationManager
.AppSettings["applicationUrl"]
+ @"/servicename/"
+ fileUpload.FileName
+ @"/" + FileType + @"/"
+ Utility.UserName + @"/"
+ Utility.EmployerID + @"/"
+ UploadedFrom);
client.Method = WebRequestMethods.Http.Post;
////the following 4 rows enable streaming
client.AllowWriteStreamBuffering = false;
client.SendChunked = true;
client.ContentType = "multipart/form-data;";
client.Timeout = int.MaxValue;
// client.KeepAlive = false;
//client.ProtocolVersion = HttpVersion.Version10;
//client.ContentLength = 0;
//client.Timeout = Timeout.Infinite;
//client.AllowWriteStreamBuffering = true;
Stream stream = fileUpload.InputStream;
if (stream.CanRead)
{ stream.Copy(client.GetRequestStream());
}
var response = new StreamReader(client.GetResponse().GetResponseStream()).ReadToEnd();
above code works fine when file to be uploaded is 2-3 MB.
it throws the error when file size is large about 8MB.
while debugging it gives me following error
System.Net.WebException was caught
HResult=-2146233079
Message=The remote server returned an error: (500) Internal Server Error.
Source=System
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at Myproject.Web.Controllers
.Employer.FileUploadController
.Upload(FileUploadViewModel fileUploadViewModel
,HttpPostedFileBase fileUpload
,String DataFileType
,String UploadedFrom)
in d:\MyProject\projNewArch\Controllers\Employer\FileUploadController.cs:line 262
InnerException:
i have tried changing the setting values which can be seen as connected.
What might be the issue? Please help
Update 1: i have IIS 8.5 at server so i think the file size (8mb) might not be the issue. Do i still need to add the some setting in web.config to allow sending big size file over POST
UPDATE 2 : Found the solution. Adding maxAllowedContentLength and maxRequestLength does the trick. Please check the link provided by Smartdev in comments section
You still need to edit your web.config file. It should look like this:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="10485760" />
</requestFiltering>
</security>
This will allow you to upload up to 10MB
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With