Below is a sub I wrote to download files by using response.binarywrite.
The code works fine, but is there any way to throttle it so that if the
clients are downloading large files (several hundred megs) they dont
take up all the bandwidth. I think the IIS version is 5, but ill
confirm that with the sys admin
thanks for ure help
:)
Private Sub streamDocs(path, filename, originalFileName, contentType)
Response.AddHeader
"content-disposition","attachment;filename="&originalFileNa me
Response.ContentType = contentType
Dim BinaryStream, Fil, fs
Set BinaryStream = CreateObject("ADODB.Stream")
set fs = Server.CreateObject("Scripting.FileSystemObject")
Set Fil = fs.GetFile(path & "\" &filename) 'Open file
BinaryStream.Type = 1
BinaryStream.Open
BinaryStream.LoadFromFile Fil.path
Response.BinaryWrite BinaryStream.Read
BinaryStream.Cancel
BinaryStream.Close
set BinaryStream = nothing
End sub
Anthony Jones wrote:
"Katie" <Dn*********@gmail.comwrote in message
news:11*********************@m79g2000cwm.googlegro ups.com...
Hi,
I am downloading files using ASP using the the binarywrite as below.
objStream.LoadFromFile(strAbsFile)
'-- send the stream in the response
Response.BinaryWrite(objStream.Read)
I was wondering is there any way I can control or throttle the
download?. I want to make sure that the users are not taking up too
much bandwidth while downloading the file.
Thanks for your help and time
:)
The only way to do this without using an additional component is to put this
file in it's own application and enable I/O throttling (although that will
apply to all downloads currently in progress).
What version of IIS are you using?
I assume you have Response.Buffer = false in the code?
You should note that even with buffer = false the buffer limit is still in
effect for any single call to BinaryWrite. On IIS6 the default limit is 4MB
hence a file larger than this will break the limit. I would recommend that
you use a for loop to chunk the contents to BinaryWrite. This does have the
effect of slowing the download (with no buffer, binarywrite will become
dependant of client acknowledgments) so use a chunk size of say 2Mb to
minimize this impact.
If you can build and use additional components you can use a chunking loop
to control bandwidth usage by using the sleep API to pause the loop a
little.
Anthony.