Amit
Amit

Reputation: 22086

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?

Upvotes: 4

Views: 7740

Answers (6)

Brian MacKay
Brian MacKay

Reputation: 32037

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

Upvotes: 9

marcoaoteixeira
marcoaoteixeira

Reputation: 505

Try this: Large file uploads in ASP.NET.

Let me know if it helps.

Upvotes: 3

Ferruccio
Ferruccio

Reputation: 100758

ASP.NET has a default limit of 4MB for file uploads. This article describes how to change that default and discusses some of the issues with uploading large files.

Upvotes: 3

user349026
user349026

Reputation:

Break it into parts, assign a sequence number to each part, upon receiving the file on the server side (assuming DB is there) collect, sort the parts according to the sequence number, and rejoin them by stripping off the sequence numbers. Hopefully you wont get timeout, if that is the only issue! Probably you could your TPL for uploads of the multiple parts and rejoin them the same way!

Upvotes: 1

Nik
Nik

Reputation: 7283

Because you are using SQL Server 2008 with its 2gb maximum for varbinary columns, you should be fine. Any regular upload script will probably work. When you get into uploads of that size though, underlying HTTP or TCP/IP connections can become a problem, but there really isn't anything you can do about that.

Upvotes: 1

Related Questions