Juan 解决方案 " Juan" < Ju ** @ discussion.microsoft.com写信息 news:71 ************************** ******** @ microsof t.com ... 嗨! 我想用ASP使用ADODB.STREAM下载大文件。对于小于80 MB的文件,它的工作非常好。 在Web服务器上我可以看到内存分配和进程w3wp是运行 。一段时间后(或多或少2分钟)我收到回复 超时。 > 以下是代码: Server.ScriptTimeout = 30000 30,000秒是一个很长的脚本超时;) Response.Buffer = True 改为False,你不想要缓冲(是的我知道你是 刷新但这更简单)。 > Response.Clear Response.Expires = 0 Response.ContentType =" ;下载文件" 如果您不知道内容类型是什么,则这不是有效的内容类型 使用后备类型:" application / octet-stream" Response.AddHeader" Content-Disposition"," attachment;文件名= QUOT; &安培; sfile 设置oStream = Server.CreateObject(" ADODB.Stream") oStream.Type = adTypeBinary oStream。打开 oStream.LoadFromFile(sfile) Response.AddHeader" Content-Length",oStream.Size'' - Sch?nheit 不要将Content-Length标题添加为重复项,ASP会为 添加它。 Response.CharSet =" UTF-8" 你怎么知道字符编码但不知道内容类型? 考虑删除这一行或设置内容 - 输入正确的文字 类型。 > For i = 0 To oStream.Size i = i + 128000 Response.BinaryWrite(oStream.Read(128000)) Response.Flush 缓冲关闭时无需刷新。 > 下一页 oStream.Close 设置oStream = Nothing Response.Flush Response.End 再次不需要冲洗和.End是严苛的,只有在你知道的情况下才使用它。如果你不知道,那么会发生一些不好的事情。即使这样设计出来的东西也不好用而不是使用.End。 > 我有吗在我的代码中更改某些内容 - 或者可能是 IIS /元数据库中的常规设置? 响应超时是客户端的事情但是通常回复 超时与获取第一块数据所需的时间相关而不是 整体发送时间。 - Anthony Jones - MVP ASP / ASP.NET Anthony写于2008年7月3日星期四14:33:27 +0100: " Juan" < Ju ** @ discussion.microsoft.com写信息 news:71 ************************** ******** @ microsof t.com ... >嗨! >我想用ASP使用ADODB.STREAM下载大文件。对于小于80 MB的文件,它工作得非常好。在Web服务器上,我可以看到内存分配和进程运行w3wp。经过一段时间(或多或少2分钟)后,我收到回复 超时。 >设置oStream = Server.CreateObject(" ADODB.Stream") oStream。 Type = adTypeBinary oStream.Open oStream.LoadFromFile(sfile) Response.AddHeaderContent-Length,oStream.Size'' - Sch?nheit 不要将Content-Length标题添加为重复,ASP为你添加 。 如果流是以块的形式写出的(它在For Next 循环中),ASP引擎如何知道最终尺寸是多少? - Dan Juan在周四写道, 2008年7月3日06:00:01 -0700: 嗨! 我想使用ASP来使用ADODB.STREAM下载大文件。对于小于80 MB的文件,它工作得非常好。 在Web服务器上,我可以看到内存分配和进程w3wp 正在运行。过了一段时间(或多或少2分钟)我收到回复 超时。 这是代码: Server.ScriptTimeout = 30000 Response.Buffer = True Response.Clear Response.Expires = 0 Response.ContentType =" Download-File" Response.AddHeader" Content-Disposition"," attachment;文件名= QUOT; & sfile 设置oStream = Server.CreateObject(" ADODB.Stream") oStream.Type = adTypeBinary oStream.Open oStream.LoadFromFile(sfile) Response.AddHeader" Content-Length",oStream.Size'' - Sch?nheit Response.CharSet =" UTF-8" For i = 0 to oStream.Size i = i + 128000 回复。 BinaryWrite(oStream.Read(128000)) Response.Flush 下一个 这看起来很奇怪 - 你''从0循环到流的大小,但你是一次推出128000字节。我认为你应该使用 For i = 0 to oStream.Size Step 128000 此外,在你的循环中当你到达结束时会发生什么流? 这是我从我的一个应用程序处理下载的方式 设置oStream = Server.CreateObject(" ADODB.Stream") 调用oStream.Open() oStream.Type = 1 调用oStream.LoadFromFile(strFilename) iDownload = 1 如果lcase(右(strfilename,4))=" .pdf"然后 Response.ContentType =" application / pdf" else Response.ContentType =" application / octet-stream" Response.AddHeaderContent-Disposition,filename =" & strfilename& " ;;" Response.Buffer = False ''以块的形式流出文件 Do While Not(oStream.EOS) Response.BinaryWrite oStream.Read(1024 * 256) 循环 oStream。关闭 设置oStream = Nothing 将文件读入流中(就像你已经拥有的那样),设置一个 相应的ContentType(如安东尼指出你使用的那个不是一个 认可的MIME类型),关闭缓冲,然后以256kB的块写出流 ,直到没有任何东西给写出来(使用 oStream.EOS来确定流是否在最后)。 你确实需要关闭缓冲 - 它''完全有可能 80MB文件超过了定义的ASP缓冲区限制,所以你得到了一个ASP错误抛出数据,这导致了什么似乎是一个 超时,但实际上是由于ASP终止脚本,因为它有错误的。到目前为止,上面的代码我已经没有比定义的ASP缓冲区限制更大的文件没有问题了,但我没有尝试过任何东西,因为 大到你的档案。 - Dan Hi!I want to use ASP to download big files using ADODB.STREAM. It works veryfine with files smaller than 80 MB.On the Webserver I can see that memory allocation and the process w3wp isrunning. After some time (more or less 2 minutes) I get a response timeout.Here is the code:Server.ScriptTimeout = 30000Response.Buffer = TrueResponse.ClearResponse.Expires = 0Response.ContentType = "Download-File"Response.AddHeader "Content-Disposition","attachment; filename=" & sfileSet oStream = Server.CreateObject("ADODB.Stream")oStream.Type = adTypeBinaryoStream.OpenoStream.LoadFromFile(sfile)Response.AddHeader "Content-Length", oStream.Size '' -- Sch??nheitResponse.CharSet = "UTF-8"For i = 0 To oStream.Sizei = i + 128000Response.BinaryWrite(oStream.Read(128000))Response.FlushNextoStream.CloseSet oStream = NothingResponse.FlushResponse.EndDo I have to change something in my code - or perhaps a general setting inIIS / the metabase?Many thanks in advanceJuan 解决方案 "Juan" <Ju**@discussions.microsoft.comwrote in messagenews:71**********************************@microsof t.com...Hi!I want to use ASP to download big files using ADODB.STREAM. It works veryfine with files smaller than 80 MB.On the Webserver I can see that memory allocation and the process w3wp isrunning. After some time (more or less 2 minutes) I get a responsetimeout.>Here is the code:Server.ScriptTimeout = 3000030,000 seconds is a long script time out ;)Response.Buffer = TrueChange to False, you don''t want to buffer anyway (yes I know you areflushing but this is simpler).>Response.ClearResponse.Expires = 0Response.ContentType = "Download-File"This is not a valid content type if you don''t know what the content type isuse the fallback type: "application/octet-stream"Response.AddHeader "Content-Disposition","attachment; filename=" & sfileSet oStream = Server.CreateObject("ADODB.Stream")oStream.Type = adTypeBinaryoStream.OpenoStream.LoadFromFile(sfile)Response.AddHeader "Content-Length", oStream.Size '' -- Sch?nheitDon''t add the Content-Length header its a duplication, ASP adds that foryou.Response.CharSet = "UTF-8"How come you know the character encoding but don''t know the content type?Consider deleting this line or setting the content-type to the correct texttype.>For i = 0 To oStream.Size i = i + 128000 Response.BinaryWrite(oStream.Read(128000)) Response.FlushNo need for a flush when buffering is off.>NextoStream.CloseSet oStream = NothingResponse.FlushResponse.EndAgain no need for a flush and .End is draconian, only use it if you knowsomething bad will happen if you don''t. Even then design out the somethingbad rather than use .End.>Do I have to change something in my code - or perhaps a general setting inIIS / the metabase?The response timeout is a clientside thing however normally responsetimeouts related to the time it takes to get the first chunk of data not theoverall send time.--Anthony Jones - MVP ASP/ASP.NETAnthony wrote on Thu, 3 Jul 2008 14:33:27 +0100:"Juan" <Ju**@discussions.microsoft.comwrote in messagenews:71**********************************@microsof t.com...>Hi!>I want to use ASP to download big files using ADODB.STREAM. It worksvery fine with files smaller than 80 MB.On the Webserver I can see that memory allocation and the processw3wp is running. After some time (more or less 2 minutes) I get aresponsetimeout.>Set oStream = Server.CreateObject("ADODB.Stream")oStream.Type = adTypeBinary oStream.Open oStream.LoadFromFile(sfile)Response.AddHeader "Content-Length", oStream.Size '' -- Sch?nheitDon''t add the Content-Length header its a duplication, ASP adds thatfor you.If the stream is being written out in chunks (which it is in the For Nextloop), how does the ASP engine know what the final size will be?--DanJuan wrote on Thu, 3 Jul 2008 06:00:01 -0700:Hi!I want to use ASP to download big files using ADODB.STREAM. It worksvery fine with files smaller than 80 MB.On the Webserver I can see that memory allocation and the process w3wpis running. After some time (more or less 2 minutes) I get a responsetimeout.Here is the code:Server.ScriptTimeout = 30000Response.Buffer = TrueResponse.ClearResponse.Expires = 0Response.ContentType = "Download-File"Response.AddHeader "Content-Disposition","attachment; filename=" &sfileSet oStream = Server.CreateObject("ADODB.Stream")oStream.Type = adTypeBinary oStream.Open oStream.LoadFromFile(sfile)Response.AddHeader "Content-Length", oStream.Size '' -- Sch?nheitResponse.CharSet = "UTF-8"For i = 0 To oStream.Size i = i + 128000 Response.BinaryWrite(oStream.Read(128000)) Response.FlushNextThis looks odd - you''re looping from 0 to the size of the stream, yet you''repushing out 128000 bytes at a time. I think you should be usingFor i = 0 To oStream.Size Step 128000Also, in your loop what happens when you reach the end of the stream?This is how I handle download from one of my applicationsSet oStream = Server.CreateObject("ADODB.Stream")Call oStream.Open()oStream.Type = 1call oStream.LoadFromFile(strFilename)iDownload = 1If lcase(right(strfilename,4)) = ".pdf" thenResponse.ContentType = "application/pdf"elseResponse.ContentType = "application/octet-stream"end ifResponse.AddHeader "Content-Disposition", "filename=" &strfilename & ";"Response.Buffer = False''stream out the file in chunksDo While Not (oStream.EOS)Response.BinaryWrite oStream.Read(1024 * 256)LoopoStream.CloseSet oStream = Nothingthis reads the file into the stream (just like you already have), sets anappropriate ContentType (as Anthony points out the one you use is not arecognised MIME type), turns off buffering, and then writes out the streamin 256kB chunks until there is nothing left to write to out (usingoStream.EOS to determine if the stream is at the end).You really do need buffering turned off - it''s entirely possible that the80MB file is going over the defined ASP buffer limit and so you''re gettingan ASP error thrown into the data, and that causes what appears to be atimeout but is actually due to ASP terminating the script because it haserrored. So far with the above code I''ve had no trouble with files largerthan the defined ASP buffer limit, but I haven''t tried it with anything aslarge as your file.--Dan 这篇关于Adodb.Stream - 问题下载大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-03 03:20