ASP经典,下载大文件在某些​​服务器上不起作用 [英] ASP Classic, Download big files does not work on certain servers

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

问题描述

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

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.

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

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

推荐答案

仅看一下代码片段就可以了,这是我用于下载大型文件的唯一方法(特别是使用Response.IsClientConnected).

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) 

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

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;

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

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

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

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

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

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.

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

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.

所以只需尝试增加CHUNK.

Const CHUNK = 20480 'Read in chunks of 20 KB

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

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