ASP Classic,在某些服务器上无法下载大文件 [英] ASP Classic, Download big files does not work on certain servers

查看:11
本文介绍了ASP Classic,在某些服务器上无法下载大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下脚本,在本地(Windows 10 IIS、Windows 2003 Server)上运行良好,但在我们的托管服务器(Windows 2003 Server)上运行良好.任何超过 4mb 的文件都会下载得很慢,然后在到达文件末尾之前超时.但是,在本地,它可以快速完整地下载.

直接下载(链接到文件本身)会在 5 秒内从我们的托管服务提供商服务器下载一个 26.5mb 的文件.因此,下载限制没有问题.托管服务器和此脚本似乎存在问题.有什么想法吗?

Response.AddHeader "content-disposition","filename=" &字符串文件名Response.ContentType = "application/x-zip-compressed" '这里是你的内容类型暗淡 strFilePath、lSize、lBlocks常量块 = 2048设置 objStream = CreateObject("ADODB.Stream")objStream.OpenobjStream.Type = 1objStream.LoadFromfile Server.MapPath("up/"&strfileName&"")lSize = objStream.SizeResponse.AddHeader "Content-Size", lSizelBlocks = 1Response.Buffer = False做直到 objStream.EOS 或没有 Response.IsClientConnectedResponse.BinaryWrite(objStream.Read(CHUNK))环形objStream.Close

解决方案

只看代码片段,它似乎很好,这正是我用来下载大文件的方法 (尤其像使用 <代码>Response.IsClientConnected).

话虽如此,读取的块的大小可能与文件的大小有关.

公式大概是这样的……

读取时间 = ((文件大小/块大小) * 读取时间)

因此,如果我们使用您的 4 MB 文件示例 (4194304 字节) 并说读取每个块需要 100 毫秒,那么以下适用;

  • 2048 字节的块大小(2 KB) 大约需要.3 分钟阅读.

  • 20480 字节的块大小(20 KB) 大约需要.阅读时间为 20 秒.

IIS 7 及更高版本上的经典 ASP 页面具有默认 scriptTimeout of 00:01:30 因此在上面的示例中,以 100 毫秒持续读取 2 KB 块的 4 MB 文件会在脚本完成之前超时.

现在这些只是粗略的统计数据,您的读取时间不会一直保持不变,它可能会快于 100 毫秒(取决于磁盘读取速度),但我认为您明白了.p>

所以只需尝试增加 CHUNK.

Const CHUNK = 20480 '读取 20 KB 的块

I have the following script, which works good, locally (Windows 10 IIS, windows 2003 Server), but not on our hosting server (Windows 2003 Server). Anything over 4mb will download really slow and then timeout before it gets to the end of the file. However, locally, it downloads fast and full.

Doing a Direct Download (link to the file itself) downloads a 26.5mb file in 5 seconds from our hosting provider server. So, there is not an issue with a download limit. There is an issue it seems, with the hosting server and this script. Any ideas?

Response.AddHeader "content-disposition","filename=" & strfileName
Response.ContentType = "application/x-zip-compressed" 'here your content -type

Dim strFilePath, lSize, lBlocks
Const CHUNK = 2048
set objStream = CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1
objStream.LoadFromfile Server.MapPath("up/"&strfileName&"") 
lSize = objStream.Size
Response.AddHeader "Content-Size", lSize
lBlocks = 1
Response.Buffer = False
Do Until objStream.EOS Or Not Response.IsClientConnected
Response.BinaryWrite(objStream.Read(CHUNK))
Loop

objStream.Close

解决方案

Just looking at the code snippet it appear to be fine and is the very approach I would use for downloading large files (especially like the use of Response.IsClientConnected).

However having said that, it's likely the size of the chunks being read in relation to the size of the file.

Very roughly the formula is something like this...

time to read = ((file size / chunk size) * read time) 

So if we use your example of a 4 MB file (4194304 bytes) and say it takes 100 milliseconds to read each chunk then the following applies;

  • Chunk Size of 2048 bytes (2 KB) will take approx. 3 minutes to read.

  • Chunk Size of 20480 bytes (20 KB) will take approx. 20 seconds to read.

Classic ASP pages on IIS 7 and above have a default scriptTimeout of 00:01:30 so in the example above a 4 MB file constantly read at 100 milliseconds in 2 KB chunks would timeout before the script could finish.

Now these are just rough statistics your read time won't constantly stay the same and it's likely faster then 100 milliseconds (depending on disk read speeds) but I think you get the point.

So just try increasing the CHUNK.

Const CHUNK = 20480 'Read in chunks of 20 KB

这篇关于ASP Classic,在某些服务器上无法下载大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆