Problem Downloading large files

Reply

Join Date: May 2004
Posts: 1
Reputation: scham is an unknown quantity at this point 
Solved Threads: 0
scham scham is offline Offline
Newbie Poster

Problem Downloading large files

 
0
  #1
May 2nd, 2004
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 "<b><p align = center> <font color=" & "#FF0000" & ">Please enter all required fields. Be sure to enter the correct number of digits.</b></font>"

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 "<b><p align = center><font color=" & "#FF0000" & ">Sorry, your file is not yet prepared or else you entered the wrong name and number codes.</b></font>"

End If

End If

%>

Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 32
Reputation: RobUK is an unknown quantity at this point 
Solved Threads: 1
RobUK RobUK is offline Offline
Light Poster

Re: Problem Downloading large files

 
0
  #2
Jul 13th, 2004
I always use these 2 functions:-
  1. Sub ForceDownload(strFilePath)
  2.  
  3. Set oFS = Server.CreateObject("Scripting.FileSystemObject")
  4. Set oFile = oFS.GetFile(strFilePath)
  5. StrFileSize = oFile.Size
  6. Set oFile = Nothing
  7. Set oFS = Nothing
  8.  
  9. Const adTypeBinary = 1
  10.  
  11. Set objStream = Server.CreateObject("ADODB.Stream")
  12. objStream.Open
  13. objStream.Type = adTypeBinary
  14. objStream.LoadFromFile strFilePath
  15.  
  16. strFileType = lcase(Right(strFilePath, 4))
  17.  
  18. ' Feel Free to Add Your Own Content-Types Here
  19. Select Case strFileType
  20. Case ".asf"
  21. ContentType = "video/x-ms-asf"
  22. Case ".avi"
  23. ContentType = "video/avi"
  24. Case ".doc"
  25. ContentType = "application/msword"
  26. Case ".zip"
  27. ContentType = "application/zip"
  28. Case ".xls"
  29. ContentType = "application/vnd.ms-excel"
  30. Case ".gif"
  31. ContentType = "image/gif"
  32. Case ".jpg", "jpeg"
  33. ContentType = "image/jpeg"
  34. Case ".wav"
  35. ContentType = "audio/wav"
  36. Case ".mp3"
  37. ContentType = "audio/mpeg3"
  38. Case ".mpg", "mpeg"
  39. ContentType = "video/mpeg"
  40. Case ".rtf"
  41. ContentType = "application/rtf"
  42. Case ".htm", "html"
  43. ContentType = "text/html"
  44. Case ".asp"
  45. ContentType = "text/asp"
  46. Case ".pdf"
  47. ContentType = "application/pdf"
  48. Case Else
  49. 'Handle All Other Files
  50. ContentType = "application/octet-stream"
  51. End Select
  52.  
  53.  
  54. Response.AddHeader "Content-Disposition", "attachment; filename=" & StripFileName(StrFilePath)
  55. Response.AddHeader "Content-Length", strFileSize
  56. ' In a Perfect World, Your Client would also have UTF-8 as the default
  57. ' In Their Browser
  58. Response.Charset = "UTF-8"
  59. Response.ContentType = ContentType
  60.  
  61. Response.BinaryWrite objStream.Read
  62. Response.Flush
  63.  
  64. objStream.Close
  65. Set objStream = Nothing
  66. End Sub
  67.  
  68. function StripFileName(ByVal asPath)
  69. if asPath = "" Then Exit function
  70. asPath = Replace(asPath, "/", "\")
  71. if InStr(asPath, "\") = 0 Then Exit function
  72. if Right(asPath, 1) = "\" Then Exit function
  73.  
  74. StripFileName = Right(asPath, Len(asPath) - InStrRev(asPath, "\"))
  75. End function
  76.  

Hope they help you.
Rob - DMOZ Editor
Web Design Forums - Free website critiques. Web design + SEO Advice
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC