 |
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

July 23rd, 2004, 10:35 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Force A File To Download
Can somebody please help me, I have been trying for days now to find out how to force mp3's to download, everything I have tried does not work. I have found this code on ASP101, and it is similar to other code that I have found. All the following code wants to do is play the file in a browser window. Any suggestion or help would be greatly appreciated.
Response.Buffer = True
Dim strFilePath, strFileSize, strFileName
Const adTypeBinary = 1
strFilePath = Request.QueryString("File")
strFileSize = Request.QueryString("Size")
strFileName = Request.QueryString("Name")
Response.Clear
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath
Response.AddHeader "Content-Disposition", "attachment; filename=" & strFileName
Response.AddHeader "Content-Length", strFileSize
Response.Charset = "UTF-8"
Response.ContentType = "audio/mpeg3"
Response.BinaryWrite objStream.Read
Response.Flush
objStream.Close
Set objStream = Nothing
Thanks
Mike
__________________
Peace
Mike
http://www.eclecticpixel.com
|

July 23rd, 2004, 11:43 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I got this to work by changing the Response.ContentType = "audio/mpeg3" to another MIME TYPE such as "application/zip". So I guess now my question would be does anybody know of a generic MIME TYPE that does not try to open the file once it is downloaded.
Thanks
|

July 23rd, 2004, 05:54 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
The trick is to set the ContentType to application/x-unknown:
Response.ContentType = "application/x-unknown"
Look here for a complete example: http://Imar.Spaanjaars.Com/QuickDocID.aspx?QUICKDOC=189
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|

July 23rd, 2004, 06:16 PM
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
Out of curiosity, I've also heard of using application/force-download.. is this different in any way from using application/x-unknown?
Snib
<><
|

July 25th, 2004, 05:29 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi Snib,
I am not quite sure on what you should "officially" pass, but application/force-download seems to work equally well (seems mostly used in PHP scripts though).
I think what's important is that you send a header that the browser doesn't know how to deal with. Registered types will cause the browser to carry out a specific task (e.g. open Word documents in the browser window etc) while everything else will force a download (as that's the only logical thing to offer when the browser doesn't know what to do with the file). I think this will work as well:
Response.ContentType = "DoesNot/Exist"
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|

July 26th, 2004, 09:21 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Just for kicks I did try all of the different content types suggested above. They will all force a file to download on a windows box and apple safari. On the apple side OS 9 and OSX explorer, it will still not download but instead it will start to play. If I change the content type to something like content type Zip, it will download then as it's suppose to it will try and unzip the file. Any suggestions on the content type on apple side with explorer? I figure I will have to do some browser detection and then find some content type that will work.
|

July 26th, 2004, 01:06 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Unfortunately, I don't know the answer to that question.
In the past I have found that browsers "sniff" the document, regardless of the content type. So, the browser looks into the file, sees it's an audio file, and then play it. I know of no way to fix this, other than configuring the client machine, which of course is not an option.
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|
 |