Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old July 23rd, 2004, 10:35 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Oklahoma City, Oklahoma, USA.
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
  #2 (permalink)  
Old July 23rd, 2004, 11:43 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Oklahoma City, Oklahoma, USA.
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
  #3 (permalink)  
Old July 23rd, 2004, 05:54 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
  #4 (permalink)  
Old July 23rd, 2004, 06:16 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Out of curiosity, I've also heard of using application/force-download.. is this different in any way from using application/x-unknown?

Snib

<><
  #5 (permalink)  
Old July 25th, 2004, 05:29 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
  #6 (permalink)  
Old July 26th, 2004, 09:21 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Oklahoma City, Oklahoma, USA.
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
  #7 (permalink)  
Old July 26th, 2004, 01:06 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Smaller download/single download file available jminatel BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 November 21st, 2005 11:10 AM
force download dialog alphyne HTML Code Clinic 1 October 25th, 2005 08:02 AM
Force a word download into a frame? interrupt Javascript How-To 1 August 15th, 2004 10:54 AM
Force A File To download harpua Javascript How-To 2 June 23rd, 2004 02:03 PM
code to force xls file to open after several hours helmekki Excel VBA 1 June 16th, 2004 02:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.