Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Upload 100MB file?

I am designing a File Server application in ASP.NET. I have to upload a file of size 100MB and then save it into SQL Server 2008 database in varbinary(max). Saving file in DB is must. I am using FileUpload control. Please suggest me how to handle such large file?
UPDATE
Any code example would be great help, any code sample?
How to read file in chunks?

like image 580
jams Avatar asked Dec 01 '22 02:12

jams


1 Answers

You can change the default limit (4mb) for a directory and its children by dropping a special web.config into that directory. That way you don't have to make your whole site allow huge uploads (doing so would open you up to a certain kinds of attacks).

Here's an example from a production app. This one is set for 200mb:

<?xml version="1.0"?>
<!-- Nested this web.config here to allow for huge uploads (up to 200mb)  -->

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

Nesting web.configs does not have any negative side-effects -- your existing web.config settings will still work site-wide, and from this directory on down, these httpRuntime settings will be inherited.

On the page that handles the upload, make sure you have a higher than normal ScriptTimeout. This is measured in seconds:

Server.ScriptTimeout = 1200;

I like setting this on the page rather than web.config because it isolates the increased timeout down to just this one page.

On the SQL side, varbinary columns can be up to 2 gigs so you're good to go there.

Update: I've used this approach with 50+ meg files, but it's possible that at the 100 meg point the standard methods might break down. There are a lot of third party controls available that could take over from there, but I would probably look hard at Telerik's RadUpload since they're a quality name and it looks very polished: RadUpload

As for your update regarding reading the file in chunks, if you really want to write that yourself, Bobby D pointed out this article: Uploading Large Files Using an HttpModule

like image 170
Brian MacKay Avatar answered Dec 04 '22 02:12

Brian MacKay