Forum Moderators: open
binData = getBinaryFile(strFile)
Response.ContentType = "image/jpeg"
Response.AddHeader "Content-Disposition", "attachment; filename=blah.jpg"
Response.Expires = 0
Response.Buffer = True
Response.Clear
Response.BinaryWrite binData
Response.Flush
Function getBinaryFile(strFilePath)
Dim TypeBinary, oStream
TypeBinary = 1 ' Indicates a binary file
' Create the object
Set oStream = Server.CreateObject("ADODB.Stream")
' Open our file
oStream.Open
' 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?
Response.Clear
Response.ContentType = "image/jpeg"
Response.AddHeader "Content-Disposition", "attachment; filename=blah.jpg"
Set objBinaryStream = Server.CreateObject("ADODB.Stream")
objBinaryStream.Type = 1
objBinaryStream.Open
objBinaryStream.LoadFromFile strFile
Response.Buffer = True
Do While Not objBinaryStream.EOS
Response.BinaryWrite objBinaryStream.Read(256000)
Loop
objBinaryStream.Close
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.