在通过asp.net fileupload控件上传一个相当大的文件(90 MB)大约2分钟后,获取ERR_CONNECTION_RESET
。
在共享主机环境上进行测试,因此我不知道到底对我执行了哪些策略。
我认为web.config设置就足够了:
<httpRuntime requestValidationMode="2.0" maxRequestLength="1000000" executionTimeout="45000" />
我应该查看其他异步文件上传控件吗?我是否缺少web.config设置?对于慢速连接的大文件,上传控件是否仅仅是不足?
最佳答案
重置连接和增加最大请求长度的工作有多种原因,但您可以考虑使用异步文件上传器。最重要的部分是使用一个将文件“分块”成较小的部分,从而避免了请求限制等。我在plupload方面拥有最佳经验:
http://www.plupload.com/
这是一些用于接收文件的代码(这是MVC,但是您可以重构为使用.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");
}
关于asp.net - 大文件的asp.net文件上传控制超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11133886/