We help IT Professionals succeed at work.

Problem to download Large mp3 file (over 4MB) using ADODB.Stream

alexmindel asked
Medium Priority
Last Modified: 2012-06-27
I created a code to download different files (jpg, gif, mp3, wma) from the client's website. I use ADODB.Stream object.
I don't have any problems with jpg and gif formats. When I try to download mp3/wma files I get IE msg: IE cannot open this site. I defined that the problem is in the file size.  If file is over 4MB (Response.BinaryWrite adoStream.Read(4194000) ) I can't download it.
I tested already different solutions like:
1. Change timeout, buffer, flush.
2. Chunk

Nothing!!! Plus I can't use any COM that needs to be registered on provider's server. Please review my code below.
I hope to get any solution ASAP.

Private Sub DownloadFile(file)
   Dim strAbsFile, objFSO, objFile, adoStream
    Response.Buffer = False
    strAbsFile = Server.MapPath(file)

    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    If objFSO.FileExists(strAbsFile) Then
        Set objFile = objFSO.GetFile(strAbsFile)
        Response.ContentType = "application/x-unknown"  
        Response.AddHeader "Content-Disposition", "attachment; filename=" & objFile.Name
        Response.AddHeader "Content-Length", objFile.Size
        Set adoStream = CreateObject("ADODB.Stream")
      adoStream.Type = 1
      Response.BinaryWrite adoStream.Read(4194000)   ' <-- if file size is over then IE Msg: IE cannot open this site.
      Set adoStream = Nothing
     end if
    Set objFile = Nothing
end sub

Watch Question

I use a slightly different function to do the same, and I haven't had a problem (other than timeing out, but that was cured by setting server.scripttimeout = 3000000), using this function

Private Sub DownloadFile(file)
      Dim strAbsFile
      Dim strFileExtension
      Dim objFSO
      Dim objFile
      Dim objStream
      strAbsFile = file
      Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
            If objFSO.FileExists(strAbsFile) Then
                  Set objFile = objFSO.GetFile(strAbsFile)
                        Response.AddHeader "Content-Disposition", "attachment; filename=" & objFile.Name
                        Response.AddHeader "Content-Length", objFile.Size
                        Response.ContentType = "application/octet-stream"
                        Set objStream = Server.CreateObject("ADODB.Stream")
                                    objStream.Type = 1
                                    Response.CharSet = "UTF-8"
                        Set objStream = Nothing
                  Set objFile = Nothing
            Else  'objFSO.FileExists(strAbsFile)
                  Response.Write("No such file exists.")
            End If
      Set objFSO = Nothing
End Sub

to use it:
Call DownloadFile(pathtothefile)

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

i've tested it with 25M files, and the only problem (minus the timeout error which I fixed) is that it takes a little time to download it, but it does work


Thank you for your quick responds. I used your function but I can't still open mp3 file.
When I click on the link "download", the download popup does not appear but looks like procedure is running.
In 2-3 minutes the blank page is opened. What do you think about it?

can you download another file type?, a .doc, .zip perhaps?


I tested txt, doc, jpg and gif. They worked fine. Zip file had a size over 4MB. Thus, I couldn't download it.
Probably, I'll not be able to download any files over 4MB.

what happens if you don't use any script...ie..link to the file itslef?


I used that last variant before and got same problem: downloaded files were corrupted.
If I use direct link to the file itself it works perfect (only popup doesn't appear). I think that is the sream object problem.
Thus, I am gonna do the following: convert mp3 files to wma format (size will be around 2MB). But It is not the real solution: problem is still there.
Thank you, kevp75, for your time and help. Let me know if you find anything else later. That would be interesting because the same problem will appear from time to time.
Best regards,

will do alex.....np
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.