Hi gang,
Have a script that works fine. However, it's really cpu intensive and
I'm looking for suggestions on a) whether or not that's normal and if
so b)a better way of doing it.
Script is very simple, there is a folder of files with numeric names.
The real file name is stored in the database. User clicks on link that
executes script and provides database record id. Record is looked up,
file name is found, and browser is delivered the binary file via
Response.BinaryWrite. Pretty basic. However, when you run it if the
file is very large at all (even 1 meg) there is a significant delay
prior to giving the user the "save, run" prompt and the cpu on the
server jumps to 50-100% utilization and stays there for quite a while.
While I know that it basically has to read the file in to stream it out
it seems like that's quite a lot of cpu processing for such a simple
task, therefore I'm wondering if it's something in my script. I've
pasted that below.
The other related question is whether there is a way to manipulate the
content-disposition header for the filename and link the browser
directly to the file instead of having to stream it? In essence the
only thing I need is to a)link browser to file for download and
b)provide proper name for file. Any help much appreciated.
[code]
' set the directory that contains the files here
strFileName = sClientFileFolderDirectory & "\" & Cstr(id)
Set Sys = Server.CreateObject( "Scripting.FileSystemObject" )
Set Bin = Sys.OpenTextFile( strFileName, 1, False )
If Sys.FileExists( strFileName ) Then
' Set the Filename to save as
Call Response.AddHeader( "Content-Disposition", "attachment;
filename=" & FileName )
' Make sure the browser downloads, instead of running it
Response.ContentType = "application/octet-stream"
' Send as a Binary Byte Stream
While Not Bin.AtEndOfStream
Response.BinaryWrite( ChrB( Asc( Bin.Read( 1 ) ) ) )
Wend
End If
Bin.Close : Set Bin = Nothing
Set Sys = Nothing
set oSession = Nothing
[code]
Cheers,
-Matt