What's Here?
- Members: 300,341
- Replies: 825,692
- Topics: 137,400
- Snippets: 4,417
- Tutorials: 1,147
- Total Online: 1,611
- Members: 111
- Guests: 1,500
|
The response object has a built in maximum on memory usage.
If you want to push files in the traditional way, that is read it in and then echo it out, you will run into this limit.
This sniplet uses chunks to get around this problem.
edit 10/09/09: fixed a bug!
|
Submitted By: Trogdor
|
|
Rating:
  
|
|
Views: 1,841 |
Language: ASP
|
|
Last Modified: September 10, 2009 |
|
Instructions: Filepath should point to the file, Filename is the name used to save the file. (dont forget the extension) |
Snippet
sub SendFileToResponse(FilePath, FileName)
dim clChunkSize, oStream, length
clChunkSize = 1048576
Response.Buffer = false
Response.ContentType = "application/octet-stream"
Response.AddHeader "Content-Disposition", "attachment; Filename=" + FileName
set oStream = Server.CreateObject("ADODB.Stream")
oStream.Type = 1
oStream.Open()
oStream.LoadFromFile(FilePath)
Response.AddHeader "Content-Length", oStream.Size
length = int (oStream.Size / clChunkSize)
if(length > 0) then
for i = 1 to length
Response.BinaryWrite oStream.Read(clChunkSize)
next
end if
if ((oStream.Size mod clChunkSize) >0) then
Response.BinaryWrite oStream.Read(oStream.Size mod clChunkSize)
end if
oStream.Close()
end sub
Copy & Paste
|
|
|
|