Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2006-03-29
9
Medium Priority
?
804 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

0
Comment
Question by:alexmindel
  • 6
  • 3
9 Comments
 
LVL 25

Accepted Solution

by:
kevp75 earned 2000 total points
ID: 16326657
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)
0
 
LVL 25

Expert Comment

by:kevp75
ID: 16326667
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
0
 

Author Comment

by:alexmindel
ID: 16328619
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?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 25

Expert Comment

by:kevp75
ID: 16329209
can you download another file type?, a .doc, .zip perhaps?
0
 

Author Comment

by:alexmindel
ID: 16332071
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.
0
 
LVL 25

Expert Comment

by:kevp75
ID: 16332174
what happens if you don't use any script...ie..link to the file itslef?
0
 
LVL 25

Expert Comment

by:kevp75
ID: 16332249
0
 

Author Comment

by:alexmindel
ID: 16332559
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.
0
 
LVL 25

Expert Comment

by:kevp75
ID: 16332602
will do alex.....np
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Loops Section Overview
Screencast - Getting to Know the Pipeline

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question