在学习动易系统过程中,建立了一个简单的网站。在做上传文件测试时发现,系统无法上传大文件,提示出错信息:“quest 对象 错误 'ASP 0101 : 80004005”,后来在网上搜索,想从谷歌或百度找出答案,但答案无非都是关联到win2003经典的 “200KB” 大小限制上。开始我也是这样认为,按照说明将MetaBase.xml中进行了相关设置:AspMaxRequestEntityAllowed="204800000" '-----最大200MB,但还是不行,最后猜测应该是Request.BinaryRead自身限制所致。后来从带进度条的无组件上传的分段传输得到启发, 原来BinaryRead方法不仅是可以读取指定大小,而且可以连续读取的。今天我就此进行了验证,发现确实可行:
PowerEasy.Upfile.asp中关于BinaryRead读取的原文片断为:
Set Forms = Server.CreateObject("Scripting.Dictionary")
Forms.CompareMode = 1
Set Files = Server.CreateObject("Scripting.Dictionary")
Files.CompareMode = 1
Set tStream = Server.CreateObject("ADODB.Stream")
Set oUpFilestream = Server.CreateObject("ADODB.Stream")
oUpFilestream.Type = 1
oUpFilestream.Mode = 3
oUpFilestream.Open
oUpFilestream.Write Request.BinaryRead(Request.TotalBytes)
oUpFilestream.Position = 0
RequestBinDate = oUpFilestream.Read
iFormEnd = oUpFilestream.size
我将其改为如下:
Dim ReadBytes,TrunkBytes,TotalBytes
ReadBytes = 0
TrunkBytes = 52428800 '--分段大小为50M,某位大大经过测试,无组件上传限制单个文件最大约≤65MB
TotalBytes = Request.TotalBytes
If TrunkBytes > TotalBytes Then TrunkBytes = TotalBytes
Set Forms = Server.CreateObject("Scripting.Dictionary")
Forms.CompareMode = 1
Set Files = Server.CreateObject("Scripting.Dictionary")
Files.CompareMode = 1
Set tStream = Server.CreateObject("ADODB.Stream")
Set oUpFilestream = Server.CreateObject("ADODB.Stream")
oUpFilestream.Type = 1
oUpFilestream.Mode = 3
oUpFilestream.Open
Do While ReadBytes < TotalBytes
oUpFilestream.Write Request.BinaryRead(TrunkBytes)
ReadBytes = ReadBytes + TrunkBytes
If (ReadBytes + TrunkBytes) > TotalBytes Then TrunkBytes = TotalBytes mod TrunkBytes '最后剩下的字节
Loop
oUpFilestream.Position = 0
RequestBinDate = oUpFilestream.Read
iFormEnd = oUpFilestream.size
修改后上传81M的文件成功(原来出错),但也有缺点,因为是二进制传输,文件大很占服务器内存。