使用ASP上传文件(最多10Mb文件大小)。净webAPI

时间:2021-12-23 01:50:30

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

我在一个VS2012 MVC4项目中工作,该项目包含一个Web API控制器。此项目将在IIS服务器上发布。

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?

我需要允许用户上传文件。问题是web API的最大上传文件大小限制为4MB。我读过(例如:http://blogs.msdn.com/b/henrikn/archive/2012/03/03/01/03/01/03/01/03/01/03/01/03/01/03/01/03/01/01/01/03/01/03/03/01/03/01/03/01/03/01/03/01/03/01/03/03/03/03/03/03/03/03/03/03/03/03/03/03/03/03/03/03/03/03/03/03/03/01/01/我不想让self托管我的webAPI因为我想把它托管在我的IIS web服务器上所以我认为这不适合我的情况,对吧?那么,对于上传大于4MB的文件,我能做些什么呢?

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

如果可能的话,我搜索HTML5解决方案(拖拽)。

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

到目前为止,我所找到的解决方案中没有一个能让我做到这一点。

Thanks for your help.

谢谢你的帮助。

3 个解决方案

#1


24  

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:

可能不清楚,但实际上博客url指的是IIS。您需要在Web中查找以下两个设置。增加上传大小:

NOTE(maxRequestLength="size in kbytes"):
<system.web> <httpRuntime targetFramework="4.5" maxQueryStringLength="" maxRequestLength="" maxUrlLength="" />

注意(maxRequestLength =“kb大小”): <系统。 "

NOTE(maxAllowedContentLength is in bytes) <system.webServer> <security> <requestFiltering> <requestLimits maxAllowedContentLength="" maxQueryString="" maxUrl=""/>

注意(maxAllowedContentLength以字节为单位) <系统。webserver> < requestfilter > < requestlimitmaxallowedcontentlength ="" maxQueryString="" maxUrl="" ""/>

#2


1  

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.

如果你仔细阅读,它会说“ASP”。NET对于你可以上传的文件大小有2G的最大限制。在ASP中托管的时候。NET/IIS您将能够接收到最多2Gbs的文件。您需要做的是在web.config中更改一些默认值。

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

看看这个:https://*.com/a/7154363/2517785

#3


0  

You can check this

你可以检查这个

 int MaxContentLength = 1024 * 1024 * 10; //Size = 10 MB
if (postedFile.ContentLength > MaxContentLength)
{


}

#1


24  

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:

可能不清楚,但实际上博客url指的是IIS。您需要在Web中查找以下两个设置。增加上传大小:

NOTE(maxRequestLength="size in kbytes"):
<system.web> <httpRuntime targetFramework="4.5" maxQueryStringLength="" maxRequestLength="" maxUrlLength="" />

注意(maxRequestLength =“kb大小”): <系统。 "

NOTE(maxAllowedContentLength is in bytes) <system.webServer> <security> <requestFiltering> <requestLimits maxAllowedContentLength="" maxQueryString="" maxUrl=""/>

注意(maxAllowedContentLength以字节为单位) <系统。webserver> < requestfilter > < requestlimitmaxallowedcontentlength ="" maxQueryString="" maxUrl="" ""/>

#2


1  

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.

如果你仔细阅读,它会说“ASP”。NET对于你可以上传的文件大小有2G的最大限制。在ASP中托管的时候。NET/IIS您将能够接收到最多2Gbs的文件。您需要做的是在web.config中更改一些默认值。

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

看看这个:https://*.com/a/7154363/2517785

#3


0  

You can check this

你可以检查这个

 int MaxContentLength = 1024 * 1024 * 10; //Size = 10 MB
if (postedFile.ContentLength > MaxContentLength)
{


}