【问题标题】:asp.net fileupload control time-out on big filesasp.net fileupload 控制大文件的超时
【发布时间】:2012-06-21 07:59:45
【问题描述】:

在通过 asp.net 文件上传控件上传一个相当大的文件 (90 MB) 大约 2 分钟后获取ERR_CONNECTION_RESET

在共享主机环境中对此进行测试,因此我不确切知道对我实施了哪些政策。

web.config 设置我认为足够了:

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

我应该查看其他异步文件上传控件吗?我是否缺少 web.config 设置?对于慢速连接上的大文件,上传控件是否根本不够用?

【问题讨论】:

  • 这是在哪个 IIS 版本上运行?
  • 根据我的主机控制面板的 IIS 7 集成模式
  • 我知道您说的是超时而不是文件大小,但这仍然可能为您指明正确的方向:blog.twinharbor.com/2011/07/28/fixing-iis7-maximum-upload-size
  • @Blachshma 实际上谢谢.. 添加 requestLimits 确实可以解决问题!欢呼声

标签: asp.net file-upload web-config


【解决方案1】:

重置连接和将最大请求长度提高到一定程度的原因可能有很多,但您对异步文件上传器的看法是正确的。最重要的部分是使用将文件“分块”成更小的部分,从而避免请求限制等。我在 plupload 方面拥有最好的经验:

http://www.plupload.com/

这是一些用于接收文件的代码(这是 MVC,但您可以重构以使用 .NET 经典中的处理程序):

       [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");
        }

【讨论】:

  • 感谢理查德的替代品!
猜你喜欢
  • 1970-01-01
  • 2016-05-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多