943,845 Members | Top Members by Rank

Ad:
  • ASP Discussion Thread
  • Unsolved
  • Views: 27325
  • ASP RSS
May 2nd, 2004
0

Problem Downloading large files

Expand Post »
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

%>

Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
scham is offline Offline
1 posts
since May 2004
Jul 13th, 2004
0

Re: Problem Downloading large files

I always use these 2 functions:-
ASP Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 1
Light Poster
RobUK is offline Offline
32 posts
since Jul 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP Forum Timeline: RDS Issue in Internet Explorer
Next Thread in ASP Forum Timeline: CDONTS email goes directly to Badmail folder





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC