in

ASP.NET Weblogs

Andy Smith's Blog

Page.RegisterStartupScript('Andy', 'MetaBuilders_WebControls_GainKnowledge();');

File Upload

A guy recently sent me an email asking about the best plan for dealing with people uploading files where the file already exists. I'm thinking somebody sent him to my site to look for the answer, but I guess that comes with the territory when you solve all the other problems. :) But I digress...

My answer was something along the lines of... “save it under a different name, write some text asking them if they want to overwrite or save as a different name, and provide a couple buttons and a textbox for the UI.”

That's pretty much the standard line everywhere. I'm not pretending to have come up with some miraculous solution... but I think it might be great to package this up as a control, incorporating the file upload control. It could be one of those “multi-view” controls that shows a different UI depending on whether a file is ready to be uploaded, or something needs to be done.

I think I could even pull off a multi-file upload scheme that could go along with this...

Comments

 

Jesse Ezell said:

Or... you could just save all files with unique identifiers or put them in the DB :-).
December 16, 2003 4:43 PM
 

Andy Smith said:

Sometimes people _do_ want to overwrite. Sometimes they don't. This is about supporting both scenarios.

As for putting files in the DB... most people are using shared hosting where they are more restricted on database size than filesystem size, and thus storing files in a DB is a major nono.
December 16, 2003 4:53 PM
 

Scott Galloway said:

DB also has the more than slight problem that you're holding the DB connection open for the duration of the reading of the file from the DB - effectively killing your connection pool performance (25 people downloading files simultaneously makes for a very slow site).
ASP.NET file upload performance is pretty nasty too unfortunately (watch your asp.net task when uploading or downloading a large file - the entire thing is held in memory before write-to-disk). The only way I can find of getting round this is using ISAPI - where I can directly access the request stream and save chunks to disk. If anyone finds a pure .NET solution, I for one would be very interested in hearing about it...
December 16, 2003 6:13 PM
 

Michael Teper said:

Check out ABCFileUpload control. You dont have to go full ISAPI, you can just implement a handler.

-Michael
December 16, 2003 6:55 PM
 

Scott Galloway said:

Maybe someone else can clarify this, but my understanding is that IIS only passes on the complete request stream to ASP.NET - so by the time an HttpHandler is able to acess the stream, the contents of the stream (including any encoded files) will be entirely in the request object in memory - not like ISAPI where you can access the individual chunks of the raw request stream and modify it. It's entirly possible I've got it worng - or that IIS 6.0 changes this behaviour...
December 16, 2003 8:15 PM
 

Faraz Beg said:

Hi...
is there a way to actually upload to an ftp server? i.e. to a server other than our web server... where we don't have any access other than ftp...

Awaiting response
January 12, 2004 4:16 PM
 

vahid said:

vahid
January 16, 2004 2:15 PM
 

Brant LeClercq said:

Using the default ASP.NET file upload method, I believe they are cached in memory before the Page_Load event is fired. However, I've used ABCUpload and it is able to stream the file to disk, minimizing server memory requirements. So it must be intercepting an earlier event. It also supports a pop-up status bar of the upload progress, which is nice.

Unfortunately, if you want to stream out files (whether from DB or file system) via ASP.Net, the entire response is buffered by asp_wp.exe or inetinfo.exe (it's been a while). Even if the user cancels the download, the file streaming in ASP.Net continues until complete, then the buffer is emptied by IIS. Streaming out a 1GB file can be hazardous to your servers health.

The only way I found around this response streaming problem is to write my own ISAPI filter, to avoid ASP.NET all together. Anyone know how to get around this within ASP.net?
April 2, 2004 9:57 AM
 

Steve West said:

I know that you can stream out a file for download fine. But can you use the input stream of the uploaded file in ASP.Net to do the same thing, or has the entire stream been loaded into memory first? ASP.Net worker process will automatically shut down when it takes more than 60% of system memory (as configured by default in the machine.config), so anyone uploading a large file may shut down and restart the ASP.net Worker Process.
June 6, 2004 5:23 PM
 

Jhai said:

How can I handle users uploading files with sizes more than what i have placed in maxRequestLength?
July 23, 2004 1:08 AM

Leave a Comment

(required)  
(optional)
(required)  
Add