Reputation: 43
I am trying to upload files to a server using the FileUpload control in ASP.Net. I want to able to upload files that exceed 1GB, and probably would never be bigger than 2GB. Currently i have this upload code:
string filename = FileUpload1.PostedFile.FileName;
filename = filename.Remove(filename.Count() - 4) + "-" + DateTime.Now.ToShortDateString() + ".zip";
filename = filename.Replace(" ", "-");
filename = filename.Replace("/", "-");
//attempt to save the file
FileUpload1.SaveAs("C:\\Uploads\\" + filename);
The error i get with this is that the server times out after a long time of trying to upload a file. I have read around extensively, and found many suggestions to do with my web.config which now looks like this:
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" maxRequestLength="999999999" executionTimeout="100000000" />
<customErrors mode="Off"/>
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="4000000000"/>
</requestFiltering>
</security>
</system.webServer>
I do not want to use a tool already written eg. NeatUpload, as i would really like to have this current code working. If anyone has any suggestions, or would like some more details please let me know, thanks.
Upvotes: 0
Views: 6627
Reputation: 34846
I understand your desire to want to get "your" code working, but you are really fighting an uphill battle with using the ASP.NET FileUpload control to upload files of the magnitude you speak of. I believe even if you get this working you will not be happy with your site's memory usage or responsiveness when someone starts uploading 1GB+ size files, let alone multiple people.
I think your better development endeavor might be a custom HTTP Handler that can chunk your file and upload in more manageable pieces, because HTTP was never designed to do massive sized file transfers which is the reason most (almost all) free and open-source alternatives to ASP.NET FileUpload either use an HTTP Handler that chunks the file or a browser extension (Flash, Silverlight, etc.) to host the chunks being sent up to the server.
NeatUpload is open sourced at CodePlex - NeatUpload
Upvotes: 1