Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Force download of file: error

Status
Not open for further replies.

travisbrown

Technical User
Dec 31, 2001
1,016
I'm trying to force download of a file rather than have the browser handle it.

This is the error I am getting. Below the error is the code I am using. Any help is appreciated.

Response object error 'ASP 0251 : 80004005'
Response Buffer Limit Exceeded
/wwsp/dlfile.asp, line 24
Execution of the ASP page caused the Response Buffer to exceed its configured limit.


<%
Response.Buffer = True

strFileName= request("file") ' Set file name

strFilePath=server.mappath("files/" & strFilename) ' Set path of file
'response.write strFilePath
'response.end
set fso=createobject("scripting.filesystemobject")
set f=fso.getfile(strfilepath)
strFileSize = f.size
set f=nothing: set fso=nothing
Const adTypeBinary = 1
Response.Clear
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath
strFileType = "audio/mpeg3" ' change to the correct content type for your file
Response.AddHeader "Content-Disposition", "attachment; filename=" & strFileName
Response.AddHeader "Content-Length", strFileSize
Response.Charset = "UTF-8"
Response.ContentType = strFileType
Response.BinaryWrite objStream.Read
Response.Flush
objStream.Close
Set objStream = Nothing
%>
 
The Buffer does have an upward limit, you may need to use a loop for your read/write instad of trying to read all and write all. you could use a while loop to read/write an arbitrary number of bytes at a time, watching the stream EOS property to see when your at the end of the stream, something like:
Code:
Do Until objStream.EOS
   Response.BinaryWrite objStream.Read 1000
   Response.Flush
Loop

The Read funciton isn't supposed to throw an error if it has fewer characters remaining then you asked for, it's supposed to just output whatever it has left and go to EOS, thus exiting from your loop. You may want to play with the number of characters your reading/writing to get some more performance since your basically forcing packets out to the target with each flush, the closer you get to making all those packets full the more efficienctly you will transfer the information and the faster things will be. I believe the maximum datapayload for an ethernet packet is something like 1474 bytes (there is overhead that needs the rest of the space). So you might be best off trying 1200-1300 bytes (there is addtl overhead for HTTP info).

-T

barcode_1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top