Hifilover
Hifilover

Reputation: 35

asp.net fileupload control time-out on big files

Getting ERR_CONNECTION_RESET after more or less 2 minutes of uploading a rather big file (90 MB) through asp.net fileupload control.

Testing this on a shared host environment so I don't know exactly what policies are enforced on me.

web.config settings are sufficient I think:

 <httpRuntime requestValidationMode="2.0" maxRequestLength="1000000" executionTimeout="45000" />

Should I be looking at other async file-upload controls? Am I missing a web.config setting? Is the upload control simply not sufficient for large files on slow connections?

Upvotes: 3

Views: 2044

Answers (1)

Richard
Richard

Reputation: 22016

There can be a number of reasons why the connection is reset and upping the max request length works to a point but you are right about looking into async file uploaders. The most important part is using one which "chunks" the files into smaller pieces and so avoids request limits etc. I have had the best experience with plupload:

http://www.plupload.com/

Here is some code for receiving the files (this is MVC but you can refactor to use a handler in .NET classic):

       [HttpPost]            
        public ActionResult UploadImage(int? chunk, int? chunks, string name)
        {
            var fileData = Request.Files[0];

            if (fileData != null && fileData.ContentLength > 0)
            {
                var path = GetTempImagePath(name);
                fileSystem.EnsureDirectoryExistsForFile(path);

                // Create or append the current chunk of file.
                using (var fs = new FileStream(path, chunk == 0 ? FileMode.Create : FileMode.Append))
                {
                    var buffer = new byte[fileData.InputStream.Length];
                    fileData.InputStream.Read(buffer, 0, buffer.Length);
                    fs.Write(buffer, 0, buffer.Length);
                }
            }

            return Content("Chunk uploaded", "text/plain");
        }

Upvotes: 1

Related Questions