954,184 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Problem Downloading large files

Currently, users can download mps files from my website PROVIDED the files are relatively small. With large files (4 mega), the files do not download. I undestand that large files must be downloaded in blocks. How does one do this??

My current code reads as follows:

<%

Set filesys = CreateObject("Scripting.FileSystemObject")

strWav = "/media/"&Request.Form("code1")&Request.Form("code2")&Request.Form("code3")&".mp3"

strFilename = server.MapPath(strWav)

if request.form("code1") = "" OR len(request.form("code1")) <5 OR request.form("code2") = "" OR len(request.form("code2")) <4 OR request.form("code3") = "ER" Then

response.write " Please enter all required fields. Be sure to enter the correct number of digits.


"

else

If filesys.FileExists(strFilename) Then

strFilename = server.MapPath(strWav)

Response.Buffer = True

Response.Clear

Set s = Server.CreateObject("ADODB.Stream")

s.Open

s.Type = 1

Set fso = Server.CreateObject("Scripting.FileSystemObject")

Set f = fso.GetFile(strFilename)

intFilelength = f.size

s.LoadFromFile(strFilename)

Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name

Response.AddHeader "Content-Length", intFilelength

Response.Charset = "UTF-8"

Response.ContentType = "application/octet-stream"

Response.BinaryWrite s.Read

Response.Flush

s.Close

Set s = Nothing

Else

response.write "Sorry, your file is not yet prepared or else you entered the wrong name and number codes.


"

End If

End If

%>

scham
Newbie Poster
1 post since May 2004
Reputation Points: 10
Solved Threads: 0
 

I always use these 2 functions:-

Sub ForceDownload(strFilePath)

	Set oFS = Server.CreateObject("Scripting.FileSystemObject")
	Set oFile = oFS.GetFile(strFilePath)
	StrFileSize = oFile.Size
	Set oFile = Nothing
	Set oFS = Nothing

	Const adTypeBinary = 1

	Set objStream = Server.CreateObject("ADODB.Stream")
	objStream.Open
	objStream.Type = adTypeBinary
	objStream.LoadFromFile strFilePath

	strFileType = lcase(Right(strFilePath, 4))
    
	' Feel Free to Add Your Own Content-Types Here
    Select Case strFileType
        Case ".asf"
            ContentType = "video/x-ms-asf"
        Case ".avi"
            ContentType = "video/avi"
        Case ".doc"
            ContentType = "application/msword"
        Case ".zip"
            ContentType = "application/zip"
        Case ".xls"
            ContentType = "application/vnd.ms-excel"
        Case ".gif"
            ContentType = "image/gif"
        Case ".jpg", "jpeg"
            ContentType = "image/jpeg"
        Case ".wav"
            ContentType = "audio/wav"
        Case ".mp3"
            ContentType = "audio/mpeg3"
        Case ".mpg", "mpeg"
            ContentType = "video/mpeg"
        Case ".rtf"
            ContentType = "application/rtf"
	Case ".htm", "html"
            ContentType = "text/html"
	Case ".asp"
            ContentType = "text/asp"
	Case ".pdf"
	    ContentType = "application/pdf"
        Case Else
            'Handle All Other Files
            ContentType = "application/octet-stream"
    End Select
	
	
	Response.AddHeader "Content-Disposition", "attachment; filename=" & StripFileName(StrFilePath)
	Response.AddHeader "Content-Length", strFileSize
	' In a Perfect World, Your Client would also have UTF-8 as the default 
	' In Their Browser
	Response.Charset = "UTF-8"
	Response.ContentType = ContentType
	
	Response.BinaryWrite objStream.Read
	Response.Flush

	objStream.Close
	Set objStream = Nothing
End Sub

function StripFileName(ByVal asPath)
    	if asPath = "" Then Exit function
    	asPath = Replace(asPath, "/", "\")
    	if InStr(asPath, "\") = 0 Then Exit function
    	if Right(asPath, 1) = "\" Then Exit function
    	
    	StripFileName = Right(asPath, Len(asPath) - InStrRev(asPath, "\"))
End function


Hope they help you.

RobUK
Light Poster
32 posts since Jul 2004
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You