0

I am using Asp.Net MVC 5 and the standard jquery plugin. I am able to upload files uptil 24MB in size to an MVC action controller. Files larger than 30MB dont get uploaded at all. The breakpoint on the MVC FileUpload actionmethod is never hit. Are there some configurations that need to be set? I searched around for some documentation but couldn't find any.

This is the setting in my web.config

 <system.web>
    <compilation debug="true" targetFramework="4.5"/>
    <httpRuntime targetFramework="4.5" maxRequestLength="2147483647" executionTimeout="1600" requestLengthDiskThreshold="2147483647" />
  </system.web>

I added this which has now allowed me to upload uptil 110MB in combined files.

 <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="2147483647" />
      </requestFiltering>
    </security>
  </system.webServer>

Still no luck with 1GB plus files. In the developer tools I get a 500 - out of memory error in the Network section when I look at the file post. How do I tweak the memory in IIS express or is this a local desktop issue?

user20358
  • 14,182
  • 36
  • 114
  • 186

2 Answers2

0

It isn't your client side code that is preventing your break point from being hit, it is the server rejecting POST requests containing the data for a file that exceeds the max bytes specified on the server.

You can specify the maximum allowed file size in bytes by adding the following to the web.config of your application:

<configuration>
  <system.web>
    <httpRuntime maxRequestLength="xxx" />
  </system.web>
</configuration>
Luke
  • 22,826
  • 31
  • 110
  • 193
0

This does not seems to be issue of coding but how much JSON data you can transfer in a single call. Have a look at this answer if you just want to update it to max length in web.config

<configuration> 
   <system.web.extensions>
       <scripting>
           <webServices>
               <jsonSerialization maxJsonLength="2147483647"/>
           </webServices>
       </scripting>
   </system.web.extensions>
</configuration> 

You can also do this in a code. Look at this answer.

protected override JsonResult Json(object data, string contentType, System.Text.Encoding contentEncoding, JsonRequestBehavior behavior) 
{ 
  return new JsonResult() { 
    Data = data, 
    ContentType = contentType, 
    ContentEncoding = contentEncoding, 
    JsonRequestBehavior = behavior, 
    MaxJsonLength = Int32.MaxValue 
  }; 
}
Community
  • 1
  • 1
  • THanks. Still getting a ' 500 Internal Server Error' when examinig the preview in Chrome Dev tools I see this -> Server Error in '/' Application. Exception of type 'System.OutOfMemoryException' was thrown. – user20358 Mar 27 '15 at 12:17
  • It means server may not have enough memory available to accommodate Huge files. I suggest you to increase timeout and also to check if server has enough memory. Alternatievly you can open buffer stream on you server to save data in temp file as they come so you dont run out of memory.Also, http requests are not meant for such purposes. If possible you might want to consider using ftp. – Nikunj Patel Mar 27 '15 at 12:30
  • Thanks. I kinda figured it could be a memory issue as the dev machine being used to run this has only 4GB ram. I still thought 1 GB would have been manageable. I did not need to modify any code for this. I used and your config suggestion to get it to work over the initial less than 30MB files so I will mark this answer as correct. – user20358 Mar 27 '15 at 12:49