Welcome to WebmasterWorld Guest from

Forum Moderators: ocean10000

Message Too Old, No Replies

Binary read of large files, needs to stream

12:29 pm on Jan 29, 2009 (gmt 0)

Full Member

10+ Year Member

joined:Aug 9, 2005
votes: 0

I am using classic ASP and I have an issue whereby I need to allow download of a large jpg file (usually 10MB) from the server.

binData = getBinaryFile(strFile)
Response.ContentType = "image/jpeg"
Response.AddHeader "Content-Disposition", "attachment; filename=blah.jpg"
Response.Expires = 0
Response.Buffer = True
Response.BinaryWrite binData

Function getBinaryFile(strFilePath)
Dim TypeBinary, oStream
TypeBinary = 1 ' Indicates a binary file
' Create the object
Set oStream = Server.CreateObject("ADODB.Stream")
' Open our file
' Retreive binary data from the file
oStream.Type = TypeBinary
oStream.LoadFromFile strFilePath
' Return the binary data to the caller
getBinaryFile = oStream.read
' Destroy the ADO object
Set oStream = Nothing
End Function

The problem is that when I call this it takes a long time for it to read in the binary file so when you are finally presented with the download box the user will probably have closed their browser. I need it to stream so that the download box pops up instantly and then you see the progress bar of your download. Any ideas?

10:51 pm on Feb 2, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 12, 2002
votes: 0

Kind of creepy, but I had an old ASP page open with your answer as I read this post:

Response.ContentType = "image/jpeg"
Response.AddHeader "Content-Disposition", "attachment; filename=blah.jpg"

Set objBinaryStream = Server.CreateObject("ADODB.Stream")
objBinaryStream.Type = 1
objBinaryStream.LoadFromFile strFile

Response.Buffer = True

Do While Not objBinaryStream.EOS
Response.BinaryWrite objBinaryStream.Read(256000)

Set objBinaryStream = Nothing

What this does is incrementally get your file and push it to the browser, rather than download it all in the background first before sending.