Uploading large files through Web API in asp.net - asp.net

I am working on Web API to upload video file.
Following code is working good for small files. I have uploaded 7mb files.
how to do multi-part video upload using api
Next i am uploading 200 mb file but it is not working throwing exception 'Request was Canceled'
I am still working on find out the details. If any one has experience in doing this can help.

Your code is probably correct since it works for small files, but don't forget to update IIS7 or IIS8's config to allow POST sizes of more than 30MB (the default limit of IIS is set to 30MB).
You'll need to edit your web.config and add this:
(in this example, it allows up to 250MB)
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="262144000"/>
</requestFiltering>
</security>
</system.webServer>

Related

How do you stop users directly accessing files on a website in IIS

I want to stop users on the internet being able to enter this URL into a browser and access these files directly. How can I do this?
note: application developed in asp.net
for example: mysite/uploadedfiles/file1.txt
is there any iis rule? Please help me.
Try to use the requestFiltering and hidden segments security feature in web.config.
<configuration>
<system.webServer>
<security>
<requestFiltering>
<hiddenSegments applyToWebDAV="false">
<add segment="uploadedfiles" />
</hiddenSegments>
</requestFiltering>
</security>
</system.webServer>
</configuration>
My advice would be not to store these files in a location which is accessible via a URL in the first place. Then the problem is solved without worrying about permissions etc.
Once the user has uploaded the file, you can store it in some other place on the server's disk - no need for it to be within the web application.
And if the file must be downloadable again later, you can write an action method to find the necessary document on disk and transmit a copy of it in the response, without the webserver ever having direct access to it.

How do I access uploaded files on Microsoft Azure websites?

I wanted to upload some audio files to my azure [ASP.NET] website. I then came up with this idea: I created a WebAPI action responsible for uploading the audio files into an UploadedAudio folder that I created inside the Content folder (wich is a public folder, right?). Everything is working just fine in Debug mode.
After publishing to Azure, I can see that the files are persisted with paths like D:\home\site\wwwroot\Content\UploadedAudio\5ab46baa-ffa7-4b7f-bbb9-9d0c53fa0751.mp3, but I'm not able to play them like I can in Debug mode, because I get a NotFound error. Here is the URL that I use https://mywebsite.azurewebsites.net/Content/UploadedAudio/5ab46baa-ffa7-4b7f-bbb9-9d0c53fa0751.mp3. In Debug mode, http://locahost:port/Content/UploadedAudio/5ab46baa-ffa7-4b7f-bbb9-9d0c53fa0751.mp3 is working fine!
How can I access the uploaded audio files?
I hope that my problem is clear enough. If someone can help me with this...
Thanks.
Got it !! adding these lines to the web.config is the solution:
<system.webServer>
<staticContent>
<mimeMap fileExtension=".mp3" mimeType="application/octet-stream" />
</staticContent>

How to upload up 10gb file on ASP.NET

I have done a application on asp.net and I'm saving a video and audio file is sql server
i have a issue with uploading big file over on sever. appls is hosted on ISS7 here i used a code in web.config file that is a below:
<httpRuntime executionTimeout="3600" maxRequestLength="102400"/>
and
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1024000000"/>
</requestFiltering>
</security>
</system.webServer>
but im getting error on uploading time that is below in image:
please help me out how can i upload files up to 10GB with ISS7
10GB file im save ing as a varbinary(MAX) and 10GB was converting in Byte
With out-of-the-box ASP.NET, you are not going to be able to upload a file that big, because IIS will either timeout or you will exceed the size limitations (read: maxRequestLength setting for IIS).
You have a few options:
Custom HTTP module
NeatUpload is a free option.
Silverlight/Flash option
SWFUpload is a free option.
Asynchronous chunking option
RadAsyncUpload - Telerik's ASP.NET AsyncUpload is a pay option, check website for pricing.
<httpRuntime executionTimeout="3600" maxRequestLength="102400"/>
is about 10Mb (maxRequestLength is in Kb - see http://msdn.microsoft.com/en-us/library/e1f13641(v=vs.100).aspx)
You try set it to 10485760...

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.
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=""/>
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
You can check this
int MaxContentLength = 1024 * 1024 * 10; //Size = 10 MB
if (postedFile.ContentLength > MaxContentLength)
{
}

asp.net - post file gives 404 page result even though posted file is well under maxRequestLength

I have a page on my ASP.NET site which uploads files.
I have attempted to tweak the web.config file to allow for larger uploads.
In my web.config, I set:
<httpRuntime maxRequestLength="2097152" executionTimeout="3600" />
On my page, when I attempt to upload smaller files, no issue...even at 25MB.
However, when I attempt to upload a 50MB file, I still get a 404 error page.
NOTE: I have a flash control on a different page which can upload almost 2gb with no issues, using this same web.config setting.
Same result on different PCs, same result when posted to different web servers.
My web server is Windows Server 2008 R2.
Any ideas of the cause? Why would flash be ok, but plain jane upload control have this problem?
I found the answer. Windows Server 2008 R2 is using IIS7 (of course), and in IIS7, you have to set the following in your web.config file (in my example to increase the limit to 2gb):
<system.webserver>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483648" />
</requestFiltering>
</security>
<system.webserver>
This worked, when everything else didn't. IIS7 by default limits uploads to 30mb unless this override is set.
The executionTimeout applies only if the debug attribute in the compilation element is False. (see also http://msdn.microsoft.com/en-us/library/e1f13641.aspx)
So try it when starting your application in Release config.

Resources