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