Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uploading files (up to 10Mb file size) with ASP.NET webAPI

I work on a VS2012 MVC4 project containing a Web API controller. This project will be published on an IIS server.

I need to allow users to upload files. The problem is a web API is limited up to 4MB maximum file size upload. I read (for example here: http://blogs.msdn.com/b/henrikn/archive/2012/03/01/file-upload-and-asp-net-web-api.aspx) that we can extend this limitation by self hosting the web API (in this case file upload up to 2GB). I don't want self host my webAPI because I want to host it on my IIS web server so I think this is not suitable for my situation, right? So what can I do for uploading files bigger than 4MB?

If possible I search for an HTML5 solution (with drag'n drop).

So far none of the solutions I found allows me to accomplish this.

Thanks for your help.

like image 452
Bronzato Avatar asked Jun 26 '13 15:06

Bronzato


People also ask

What is the maximum file size for API?

The maximum size of the files for upload using the REST API is 100MB.


2 Answers

Probably it was not clear but actually the blog URL is referring to IIS. You need to look for the following 2 settings in Web.config to increase the upload size:

Note maxRequestLength is in kbytes:

<system.web>
  <httpRuntime targetFramework="4.5" maxQueryStringLength="" maxRequestLength="" maxUrlLength="" />

Note maxAllowedContentLength is in bytes:

<system.webServer>
  <security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="" maxQueryString="" maxUrl=""/>
like image 63
Kiran Avatar answered Sep 28 '22 02:09

Kiran


If you read it carefully, it says "ASP.NET has a maximum limit of 2G in terms of file size that you can upload." So basically when hosted in ASP.NET/IIS you will be able to receive files up to 2Gbs. What you have to do is change some default values in web.config.

Check this out: https://stackoverflow.com/a/7154363/2517785

like image 34
Ilkka Avatar answered Sep 28 '22 02:09

Ilkka