1

How to upload large files in ASP.Net MVC 4

I have code like this in the controller:

Request.Files.Get("img").SaveAs(Server.MapPath("~/Images/ImgSong/" + +Out.Id + ".jpg"));

It only allows uploading a small file, while the file I want to upload would range from 10Mb to 100Mb.

Please help me.

Trevor Reid
  • 3,310
  • 4
  • 27
  • 46
anosoul
  • 13
  • 5

2 Answers2

2

You need to change you web.config:

<configuration>
  <system.web>
    <httpRuntime maxRequestLength="4096" />
  </system.web>
</configuration>

The default value is 4096kb. You need to change this value to 10240 for 10mb uploading.

Trevor Reid
  • 3,310
  • 4
  • 27
  • 46
Ozan Yurtseven
  • 810
  • 8
  • 17
  • I have to do what you instruct but still an error, here is the picture![enter image description here][1] http://i.stack.imgur.com/y6xVK.png – anosoul Jul 02 '14 at 08:26
  • This error means you have tag on web.config but don't have configsections. Can you try only with my code if not run than try only @Kamlesh's code.By the way you have already section. You need to write httpruntime thing only. – Ozan Yurtseven Jul 02 '14 at 08:38
0

Edit your web.config as per size of file.

<system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" maxRequestLength="10240" executionTimeout="1600" requestLengthDiskThreshold="10240" />
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="10240" />
      </requestFiltering>
    </security>
    ...
</system.web>
Kamlesh Arya
  • 4,864
  • 3
  • 21
  • 28