ASP force file download for SWF. Works with non SWF files but not with SWF files
Posted on 2007-10-09
I have built a script that forces a file download.
I want our viewers to have to download the Flash file and not view it in their browser.
The file works perfectly in all aspects. It checks file existance, it brings up the downloads, but when I try it with SWF files, which is what I want it for, then it doesn't work. Well it does download the "file" but instead of it being the usual 4MB (test file) it downloads a 1KB file. This only happening with SWF files. It works perfectly with word files, text files, HTML files etc.
I even tried using the direct mime type for the ContentType (application/x-shockwave-flash) but it is not working at all.
Here is my code...
Thanks in advance,
dim theFile, theExt, theFullFileName, theActualFile, theLocation, FileSystemObj
const adTypeBinary = 1
' get the file
theExt = ".swf"
theFile = Request("file")
theFullFileName = theFile & theExt
' file location
theLocation = Server.MapPath("\videos") & "\"
theActualFile = theLocation & theFullFileName
' start check on file existance
set FileSystemObj = Server.CreateObject("Scripting.FileSystemObject")
' error checking
' filename not specified
if theFile = "" then
Response.Write("A filename was not specified")
' if the query is not empty check for existance
' file does not exist
if FileSystemObj.FileExists(theActualFile)=false then
Response.Write("The file you specified does not exist")
' file exists and we can continue with the download
' add headers
Response.ContentType = "application/octet-stream"
Response.AddHeader "content-disposition", "attachment; filename=" & theFullFileName
set FileStream = Server.CreateObject("ADODB.Stream")
FileStream.Type = adTypeBinary
while not FileStream.EOS
Response.BinaryWrite FileStream.Read(1024 * 64)
Set FileStream = Nothing