• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 851
  • Last Modified:

ASP force file download for SWF. Works with non SWF files but not with SWF files

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,

Byron

====================================

<%

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")
else
      
      ' 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")
      else
            
            ' 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
            FileStream.Open
            FileStream.LoadFromFile theActualFile
            while not FileStream.EOS
                  Response.BinaryWrite FileStream.Read(1024 * 64)
            wend
            FileStream.Close
            Set FileStream = Nothing
            response.Flush
            response.End

      end if
      
end if

%>
0
byronrode
Asked:
byronrode
1 Solution
 
GawaiCommented:
0
 
GawaiCommented:
or replace
Response.ContentType = "application/octet-stream"

with

Response.ContentType = "application/x-msdownload"
0
 
byronrodeAuthor Commented:
@gawai:

Will look at the URL.
Changing the content-type doesn't work either, still downloads a 1Kb file.

Any other ideas?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
byronrodeAuthor Commented:
@gawai:

Todd Woolums script is far to big for what I need. In essence I only need 3 files to be downloaded, but I want to force the user to download the file.
0
 
GawaiCommented:
0
 
R_HarrisonCommented:
Have you tried...
Response.AddHeader "Content-Disposition","attachment;filename=yourfile.swf"
0
 
byronrodeAuthor Commented:
@gawai:

Ok it doesn't have anything to do with my script at all. My script is working perfectly.
It has to do with the Buffer limit set in Windows. The maximum file size is apparently 4mb. I tested with another SWF file below 4 Mb and it worked perfectly. I tried several different files under 4Mb and they all work.

@R Harrison:
I had tried that in the beginning.

@all:

In order to solve this problem you need to edit the metabase.xml file and increase the buffer limit. This only works for Windows Server 2K3, for other versions of Windows (2K and XP) you need to download a program called Meta Edit from Microsoft as the file is a BIN file.
0
 
Computer101Commented:
PAQed with points refunded (200)

Computer101
EE Admin
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now