We help IT Professionals succeed at work.

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

alexmindel
alexmindel asked
on
Medium Priority
866 Views
Last Modified: 2012-06-27
Hi,
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.
Thanks.

*******************************************************************************
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.Open()
      adoStream.Type = 1
      adoStream.LoadFromFile(strAbsFile)
      Response.BinaryWrite adoStream.Read(4194000)   ' <-- if file size is over then IE Msg: IE cannot open this site.
      adoStream.Close
      Set adoStream = Nothing
      Response.End
     end if
    Set objFile = Nothing
end sub

Comment
Watch Question

Commented:
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.Clear
                        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.Open
                                    objStream.Type = 1
                                    Response.CharSet = "UTF-8"
                                    objStream.LoadFromFile(strAbsFile)
                                    Response.BinaryWrite(objStream.Read)
                              objStream.Close
                        Set objStream = Nothing
                  Set objFile = Nothing
            Else  'objFSO.FileExists(strAbsFile)
                  Response.Clear
                  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

Commented:
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

Author

Commented:
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?

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

Author

Commented:
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.

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

Author

Commented:
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,
Alex.

Commented:
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.

OR

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.