throttling download in ASP

K

Katie

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

:)
 
A

Anthony Jones

Katie said:
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.
 
K

Katie

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="&originalFileName
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
 
A

Anthony Jones

Katie said:
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="&originalFileName
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

This doesn't really tell me anything new. The short answer is no.
However the advice I have already given still stands.

BTW why FileSystemObject? doesn't:-

BinaryStream.LoadFromFile path & "\" & filename

work for you?

Also what does:-

BinaryStream.Cancel

do?
 
B

B

Hi,

Thanks for your email.
I am a little confused regarding the loop you are talking about.

I appologize for posting on more than one group, i wasnt sure which
group this would fit under

Thanks
:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top