且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ASP经典,下载大文件在某些​​服务器上不起作用

更新时间:2023-10-12 13:13:28

仅看一下代码片段就可以了,这是我用于下载大型文件的唯一方法(特别是使用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