Reply
Force Download Question
Old 06-09-2004, 01:18 PM Force Download Question
Novice Talker

Posts: 6
Trades: 0
Hi

I'm having a bit of trouble with the script below. I use this to force MP3 files to download instead of open up in a browser. This works fine EXCEPT that it doesn't allow files over 4MB to download. Why is this? If I type the complete file name in the address bar of IE (i.e. "www.mysite.com/download/mysong.mp3"), it downloads fine. Any ideas?

Thanks

M

*****

<%@LANGUAGE="VBSCRIPT"%>
<%
Response.Buffer=true
On Error Resume Next
'Create a stream object
Dim tfm_downloadStream
Set tfm_downloadStream = Server.CreateObject("ADODB.Stream")
tfm_downloadStream.Type = 1
tfm_downloadStream.Open
tfm_downloadStream.LoadFromFile Server.Mappath(Request.Form("FileTitle"))
If Err.number = 0 Then
Response.Clear
Response.ContentType = "application/octet-stream"
Response.AddHeader "Content-Disposition", "attachment; filename=NewDownload.mp3"
Response.AddHeader "Content-Transfer-Encoding","binary"
Response.BinaryWrite tfm_downloadStream.Read
tfm_downloadStream.Close
Set tfm_downloadStream = Nothing
Response.End()
Else
tfm_downloadStream.Close
Set tfm_downloadStream = Nothing
Response.Redirect("error.asp")
End If
%>
MichaelThomas is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 06-09-2004, 10:52 PM
The Dorian's Avatar
Skilled Talker

Posts: 74
Location: Orange County, California
Trades: 0
What error are you getting? Please elaborate.
__________________
Dorian Collier
my blog - dorkian.com
Free Pay-Per-Click ROI Calculator
The Dorian is offline
Reply With Quote
View Public Profile Visit The Dorian's homepage!
 
Old 06-10-2004, 05:35 AM
Novice Talker

Posts: 6
Trades: 0
No error message. The file appears to download in less than a second but is zero kb in size. It looks like and MP3 but there's nothing in it! Only applies to files over 4MB. Under 4MB, the process works fine.

M
MichaelThomas is offline
Reply With Quote
View Public Profile
 
Old 06-10-2004, 03:48 PM Wow :(
The Dorian's Avatar
Skilled Talker

Posts: 74
Location: Orange County, California
Trades: 0
Hmmm...tuff one. I'll ask some people if they have any ideas.

Good luck!
__________________
Dorian Collier
my blog - dorkian.com
Free Pay-Per-Click ROI Calculator
The Dorian is offline
Reply With Quote
View Public Profile Visit The Dorian's homepage!
 
Old 06-14-2004, 04:29 PM
Anacrusis's Avatar
Defies a Status

Posts: 2,099
Name: Adam
Location: Colchester CT
Trades: 0
Try here:
http://www.maximumasp.com/maxtrack.asp?kb=790
Anacrusis is offline
Reply With Quote
View Public Profile Visit Anacrusis's homepage!
 
Old 12-13-2005, 07:48 PM Possible Solution (works for me)
Junior Talker

Posts: 1
Trades: 0
when downloading large files, even if we had response.buffer set to false this would be an issue since we are trying to send all the content to the client at one time
Code:
Response.BinaryWrite tfm_downloadStream.Read
.

however, what I did was, read the file in chunks just smaller than the maximum buffer size, this seems to work very efficiently for me:
Code:
 
<%
 do while not tfm_downloadStream.EOS
   '3670016 = 3.5 MB (the IIS limit is 4 MB)
  response.binaryWrite tfm_downloadStream.read(3670016) 
  response.flush
 loop
%>
Please let me know if this helps or if there is any reason this should not be done.
webProgrammer is offline
Reply With Quote
View Public Profile
 
Old 10-13-2008, 09:12 AM Re: Force Download Question
Junior Talker

Posts: 1
Name: spud
Trades: 0
Hi yea,
I have files that are nearly 15 meg in size. regarding "the IIS limit is 4 MB"


<%
do while not tfm_downloadStream.EOS
'3670016 = 3.5 MB (the IIS limit is 4 MB)
response.binaryWrite tfm_downloadStream.read(3670016)
response.flush
loop
%>

Can you advise at all


cheers

spud
twocans is offline
Reply With Quote
View Public Profile
 
Old 10-17-2008, 12:17 AM Re: Force Download Question
Sean@WMS's Avatar
Skilled Talker

Posts: 52
Name: Sean Connors
Location: Eureka, CA USA
Trades: 0
Quote:
Originally Posted by twocans View Post
Hi yea,
I have files that are nearly 15 meg in size. regarding "the IIS limit is 4 MB"


<%
do while not tfm_downloadStream.EOS
'3670016 = 3.5 MB (the IIS limit is 4 MB)
response.binaryWrite tfm_downloadStream.read(3670016)
response.flush
loop
%>
Now this an interesting approach; I never thought of buffering a file download like this. Nice workaround.

The issue here is that a Windows server will only push upto 4 MB in a response; if the data in the response is over 4 MB, the server won't be able to push the whole response. However, that is just a default setting in the IIS Metabase. Another way to deal with this is to go into the IIS Metabase and change the allocation allowed on the site for a response to whatever your upper bound is.

Frankly, I like the response buffering approach better; I'll have to try that at my next opportunity.
__________________
Web Merchant Services
Online Payment Processing, FREE shopping cart
Sean@WMS is offline
Reply With Quote
View Public Profile Visit Sean@WMS's homepage!
 
Reply     « Reply to Force Download Question
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.16159 seconds with 13 queries