• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 857
  • 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
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

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