Adodb.Stream - 问题下载大文件 [英] Adodb.Stream - Problem download big files

查看:61
本文介绍了Adodb.Stream - 问题下载大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我想用ASP下载使用ADODB.STREAM的大文件。对于小于80 MB的文件,它的工作非常好。

在Web服务器上我可以看到内存分配和进程w3wp是运行
。一段时间后(或多或少2分钟)我得到一个响应超时。


这是代码:


Server.ScriptTimeout = 30000

Response.Buffer = True


Response.Clear

Response.Expires = 0

回复.ContentType =" Download-File"

Response.AddHeader" Content-Disposition"," attachment;文件名= QUOT; &安培; sfile


设置oStream = Server.CreateObject(" ADODB.Stream")

oStream.Type = adTypeBinary

oStream。打开

oStream.LoadFromFile(sfile)

Response.AddHeaderContent-Length,oStream.Size'' - Sch ?? nheit

Response.CharSet =" UTF-8"


for i = 0 to oStream.Size

i = i + 128000

Response.BinaryWrite(oStream.Read(128000))

Response.Flush


下一页


oStream 。关闭

设置oStream =没什么

Response.Flush

Response.End


我是我必须在我的代码中更改一些内容 - 或者可能是一般设置

IIS /元数据库?


非常感谢提前

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,你不想要缓冲(是的我知道你是

刷新但这更简单)。
< blockquote class =post_quotes>
>

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 very
fine with files smaller than 80 MB.
On the Webserver I can see that memory allocation and the process w3wp is
running. After some time (more or less 2 minutes) I get a response timeout.

Here is the code:

Server.ScriptTimeout = 30000
Response.Buffer = True

Response.Clear
Response.Expires = 0
Response.ContentType = "Download-File"
Response.AddHeader "Content-Disposition","attachment; filename=" & sfile

Set 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
Response.BinaryWrite(oStream.Read(128000))
Response.Flush

Next

oStream.Close
Set oStream = Nothing
Response.Flush
Response.End

Do I have to change something in my code - or perhaps a general setting in
IIS / the metabase?

Many thanks in advance

Juan

解决方案

"Juan" <Ju**@discussions.microsoft.comwrote in message
news:71**********************************@microsof t.com...

Hi!
I want to use ASP to download big files using ADODB.STREAM. It works very
fine with files smaller than 80 MB.
On the Webserver I can see that memory allocation and the process w3wp is
running. After some time (more or less 2 minutes) I get a response

timeout.

>
Here is the code:

Server.ScriptTimeout = 30000

30,000 seconds is a long script time out ;)

Response.Buffer = True

Change to False, you don''t want to buffer anyway (yes I know you are
flushing but this is simpler).

>
Response.Clear
Response.Expires = 0
Response.ContentType = "Download-File"

This is not a valid content type if you don''t know what the content type is
use the fallback type: "application/octet-stream"

Response.AddHeader "Content-Disposition","attachment; filename=" & sfile

Set oStream = Server.CreateObject("ADODB.Stream")
oStream.Type = adTypeBinary
oStream.Open
oStream.LoadFromFile(sfile)
Response.AddHeader "Content-Length", oStream.Size '' -- Sch?nheit

Don''t add the Content-Length header its a duplication, ASP adds that for
you.

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 text
type.

>
For i = 0 To oStream.Size
i = i + 128000
Response.BinaryWrite(oStream.Read(128000))
Response.Flush

No need for a flush when buffering is off.

>
Next

oStream.Close
Set oStream = Nothing
Response.Flush
Response.End

Again no need for a flush and .End is draconian, only use it if you know
something bad will happen if you don''t. Even then design out the something
bad rather than use .End.

>
Do I have to change something in my code - or perhaps a general setting in
IIS / the metabase?

The response timeout is a clientside thing however normally response
timeouts related to the time it takes to get the first chunk of data not the
overall send time.

--
Anthony Jones - MVP ASP/ASP.NET


Anthony wrote on Thu, 3 Jul 2008 14:33:27 +0100:

"Juan" <Ju**@discussions.microsoft.comwrote in message
news:71**********************************@microsof t.com...

>Hi!

>I want to use ASP to download big files using ADODB.STREAM. It works
very fine with files smaller than 80 MB.
On the Webserver I can see that memory allocation and the process
w3wp is running. After some time (more or less 2 minutes) I get a
response

timeout.

>Set oStream = Server.CreateObject("ADODB.Stream")
oStream.Type = adTypeBinary oStream.Open oStream.LoadFromFile(sfile)
Response.AddHeader "Content-Length", oStream.Size '' -- Sch?nheit

Don''t add the Content-Length header its a duplication, ASP adds that
for you.

If the stream is being written out in chunks (which it is in the For Next
loop), how does the ASP engine know what the final size will be?

--
Dan


Juan wrote on Thu, 3 Jul 2008 06:00:01 -0700:

Hi!

I want to use ASP to download big files using ADODB.STREAM. It works
very fine with files smaller than 80 MB.
On the Webserver I can see that memory allocation and the process w3wp
is running. After some time (more or less 2 minutes) I get a response
timeout.

Here is the code:

Server.ScriptTimeout = 30000
Response.Buffer = True

Response.Clear
Response.Expires = 0
Response.ContentType = "Download-File"
Response.AddHeader "Content-Disposition","attachment; filename=" &
sfile

Set 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
Response.BinaryWrite(oStream.Read(128000))
Response.Flush
Next

This looks odd - you''re looping from 0 to the size of the stream, yet you''re
pushing out 128000 bytes at a time. I think you should be using

For i = 0 To oStream.Size Step 128000
Also, in your loop what happens when you reach the end of the stream?
This is how I handle download from one of my applications

Set oStream = Server.CreateObject("ADODB.Stream")
Call oStream.Open()
oStream.Type = 1
call oStream.LoadFromFile(strFilename)

iDownload = 1
If lcase(right(strfilename,4)) = ".pdf" then
Response.ContentType = "application/pdf"
else
Response.ContentType = "application/octet-stream"
end if
Response.AddHeader "Content-Disposition", "filename=" &
strfilename & ";"

Response.Buffer = False

''stream out the file in chunks
Do While Not (oStream.EOS)
Response.BinaryWrite oStream.Read(1024 * 256)
Loop

oStream.Close
Set oStream = Nothing
this reads the file into the stream (just like you already have), sets an
appropriate ContentType (as Anthony points out the one you use is not a
recognised MIME type), turns off buffering, and then writes out the stream
in 256kB chunks until there is nothing left to write to out (using
oStream.EOS to determine if the stream is at the end).

You really do need buffering turned off - it''s entirely possible that the
80MB file is going over the defined ASP buffer limit and so you''re getting
an ASP error thrown into the data, and that causes what appears to be a
timeout but is actually due to ASP terminating the script because it has
errored. So far with the above code I''ve had no trouble with files larger
than the defined ASP buffer limit, but I haven''t tried it with anything as
large as your file.

--
Dan


这篇关于Adodb.Stream - 问题下载大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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