"Response Buffer Limit Exceeded" ASP Solution to having to sending a large file
Thursday, April 12, 2007
So lately I have been working in old skool ASP. I hit the problem of sending a large exe file to a client the file size was 30 Meg. A couple of searches all turned to this page.
http://www.fogcreek.com/FogBugz/KB/errors/ResponseBufferLimitExceed.html
So I phoned my hosting company.. who promptly said no to my request to change the AspBufferingLimit . Not suprising this is the limit that stops a infinite loop from consuming the server.
So a few more google pages later and bit of hacking I have hopefully a working solution togther.
Hopefully this might be useful for someone in the future.
Response.AddHeader "Content-Disposition", "attachment; filename=mylargedownload.exe"
Response.AddHeader "Content-Transfer-Encoding","binary"
Response.ContentType = "application/octet-stream"
Const adTypeBinary = 1
Dim strFilePath
strFilePath = Server.Mappath("/download/mylargedownload.exe")
'This is the path to the file on disk.
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath
'1 MB
clChunkSize = 1048576
Dim i
For i = 0 To objStream.Size \ clChunkSize
Response.BinaryWrite objStream.Read(clChunkSize)
Response.Flush
Next
objStream.close
Set objStream = Nothing
Labels: ASP


0 Comments:
Post a Comment
<< Home