Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-06-2012, 08:20 PM   PM User | #1
germus
New to the CF scene

 
Join Date: Oct 2012
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
germus is an unknown quantity at this point
forcing asp download problems with large files

I use this code to force the download files:

<%
file = Request.QueryString("file")
path=Request.QueryString("dir")+file
ContentType = "application/x-msdownload"
Response.Buffer = True
Const adTypeBinary = 1
Response.Clear
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile Server.MapPath(path)
ContentType = "application/octet-stream"
Response.AddHeader "Content-Disposition", "attachment; filename=" & file
Response.Charset = "UTF-8"
Response.ContentType = ContentType
Response.BinaryWrite objStream.Read
Response.Flush
objStream.Close
Set objStream = Nothing
%>

it works very well !

But I have a problem with files size large ...
there is anyone to help me?
germus is offline   Reply With Quote
Old 10-08-2012, 07:04 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,237
Thanks: 59
Thanked 3,998 Times in 3,967 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
It depends on where your problem is.

If the file is too large to load into the stream with LoadFromFile then there is no easy answer.

If the problem is simply that your Response buffer is too small, then it's fixable.

objStream.Read can take one argument: The number of bytes to read. So you can do this in chunks.

EXAMPLE ONLY:

In place of
Code:
Response.BinaryWrite objStream.Read
you could try doing:
Code:
CONST CHUNK = 100000 ' experiment to get best chunk size
byteCount = objStream.Size
Do While byteCount > CHUNK
    Response.BinaryWrite objStream.Read(CHUNK)
    Response.Flush
    byteCount = byteCount - CHUNK
Loop
Response.BinaryWrite objStream.Read(byteCount)
This is untested code. I remember doing something like this almost 10 years ago, so I'm really dredging this out of vary old human memory. (Both the human and the memory are old.)
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 10-08-2012, 08:55 AM   PM User | #3
germus
New to the CF scene

 
Join Date: Oct 2012
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
germus is an unknown quantity at this point
solved !

In place of

Response.BinaryWrite objStream.Read

I tried

Do While Not objStream.EOS
Response.BinaryWrite objStream.Read(4096)
Response.Flush
Loop

it works perfectly
germus is offline   Reply With Quote
Old 10-08-2012, 10:46 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,237
Thanks: 59
Thanked 3,998 Times in 3,967 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Yes, same idea as what I gave. Simpler coding, but would be same result: Just do it in "chunks". But 4096 is a very tiny chunk size. Not very efficient. You really should try increasing the chunk size *A LOT* to find the optimum size.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:18 PM.


Advertisement
Log in to turn off these ads.