使用Adodb.Stream下載文件(如下代碼)。
Response.ContentType = "application/octet-stream"
response.AddHeader "Content-Disposition","attachment;filename=" & objRs("Attach_Name")& filetype
Set Stream = Server.CreateObject("ADODB.Stream")
Stream.type=1
Stream.Open
Stream.LoadFromFile server.mappath(objRs("Attach_path"))
Response.BinaryWrite Stream.Read
Stream.Close
Set Stream = Nothing
當(dāng)下載文件小于4M時(shí)沒問題,大于4M時(shí)出錯(cuò),提示 :
Response對(duì)象錯(cuò)誤 'ASP 0251 : 80004005'
超過(guò)響應(yīng)緩沖區(qū)限制
問題出在IIS的配制中AspBufferingLimit只有4M,所以有如下幾種解決辦法:
1、修改IIS的配制
停止IIS服務(wù),然后用記事本修改C:\WINDOWS\system32\inetsrv\MetaBase.xml
中的:
AspBufferingLimit="4194304" //即默認(rèn)4M
改為:
AspBufferingLimit="8388608" //改為8M或更多,自己決定
2、如果不想修改IIS的默認(rèn)配制就要修改代碼了。
Response.Buffer=False ‘將Response.Buffer設(shè)為否
Response.ContentType = "application/octet-stream"
response.AddHeader "Content-Disposition","attachment;filename=" & objRs("Attach_Name")& filetype
Set Stream = Server.CreateObject("ADODB.Stream")
Stream.type=1
Stream.Open
Stream.LoadFromFile server.mappath(objRs("Attach_path"))
offset = 0
ChunkSize = 2048*1024 ‘ChunkSize小于IIS配制文件中的AspBufferingLimit項(xiàng)所設(shè)置的大小
TotalSize = Stream.Size
while offset < TotalSize
if (TotalSize - offset < ChunkSize) then
ChunkSize = TotalSize – offset
end if
strChunk = Stream.Read(ChunkSize)
Response.BinaryWrite strChunk
offset = offset + ChunkSize
wend
Stream.Close
或者
Response.Buffer= true ‘使用緩沖區(qū)
Response.Clear
Response.ContentType = "application/octet-stream"
response.AddHeader "Content-Disposition","attachment;filename=" & objRs("Attach_Name")& filetype
Set Stream = Server.CreateObject("ADODB.Stream")
Stream.type=1
Stream.Open
Stream.LoadFromFile server.mappath(objRs("Attach_path"))
offset = 0
ChunkSize = 2048*1024
TotalSize = Stream.Size
while offset < TotalSize
if (TotalSize - offset < ChunkSize) then
ChunkSize = TotalSize – offset
end if
strChunk = Stream.Read(ChunkSize)
Response.BinaryWrite strChunk
response.flush ‘這句很重要,它把緩沖區(qū)的數(shù)據(jù)據(jù)推出去
offset = offset + ChunkSize
wend
Stream.Close
該文章在 2011/3/17 10:12:49 編輯過(guò)